将包含特殊字符的字符串变量分配给字符串 属性 会丢失特殊字符
Assigning a string variable that contains special characters to a string property looses special characters
我有如下声明:
string city = HandleTypeString(address.City, tokenParams);
address.City = city; //"_rv!9yfEEZy";
handleTypeString
return 是一个带有随机特殊字符的字符串 (_rv!9yfEEZy)
。当我将值保存在 city
变量中时,它包含 handleTypeString
return 的所有内容,但是当我将它分配给 address.city
时,它变成 rv9yfEEZy
丢失特殊字符.我需要在 属性 中存储准确的值。如何在赋值时保留原始值?
编辑:
我发现 属性 setter 正在删除那些特殊字符的问题。
public 字符串城市 { 获取 { return this._City; } set { this._City = value.RemoveDiacritics().RemoveSpecialCharacters(); } }
我的代码随机失败,因为加密值每次都不包含特殊字符。谢谢大家建议检查 属性 定义。
address.City
修改 setter 或 getter 中提供的值。例如:
private string city;
public string City
{
get { return city; }
set { city = RemoveSpecialCharacters(value); }
}
或
private string city;
public string City
{
get { return RemoveSpecialCharacters(city); }
set { city = value; }
}
我有如下声明:
string city = HandleTypeString(address.City, tokenParams);
address.City = city; //"_rv!9yfEEZy";
handleTypeString
return 是一个带有随机特殊字符的字符串 (_rv!9yfEEZy)
。当我将值保存在 city
变量中时,它包含 handleTypeString
return 的所有内容,但是当我将它分配给 address.city
时,它变成 rv9yfEEZy
丢失特殊字符.我需要在 属性 中存储准确的值。如何在赋值时保留原始值?
编辑: 我发现 属性 setter 正在删除那些特殊字符的问题。 public 字符串城市 { 获取 { return this._City; } set { this._City = value.RemoveDiacritics().RemoveSpecialCharacters(); } }
我的代码随机失败,因为加密值每次都不包含特殊字符。谢谢大家建议检查 属性 定义。
address.City
修改 setter 或 getter 中提供的值。例如:
private string city;
public string City
{
get { return city; }
set { city = RemoveSpecialCharacters(value); }
}
或
private string city;
public string City
{
get { return RemoveSpecialCharacters(city); }
set { city = value; }
}