简体   繁体   English

如何修剪琴弦?

[英]How to trim a string?

Value of rate.TierId is ' Zone1_ResidentialSales_LoansEscrowServices'. rate.TierId的值是“ Zone1_ResidentialSales_LoansEscrowServices”。 i have two spaces in start of string.I want to remove those spaces. 我在string。开头有两个空格。我想删除这些空格。 I used below code, but ot's not working' 我使用下面的代码,但无法正常工作'

rate.TierId.ToString().Trim()

please sugeest me some other way 请以其他方式建议我

string trimmedString = rate.TierId.ToString().Trim();

In addition to using trim() you could try using string.replace(oldValue, newValue). 除了使用trim()之外,您还可以尝试使用string.replace(oldValue,newValue)。

When using the replace method you need to specify the value equating to itself eg 使用replace方法时,您需要指定等于其自身的值,例如

yourString = yourString.replace(" ", "");

字符串是不可变的,请使用新的字符串变量。

string trimmedRate = rate.TierId.ToString().Trim();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM