今天两个不同系统的对接,出现了数据不能打印的问题,查了下是特殊字符造成的
首先楼主先打印出该字符的ascll编码,代码如图:
String c= "(3";
byte[] array = System.Text.Encoding.ASCII.GetBytes(c); //数组array为对应的ASCII数组
string ASCIIstr2 = null;
for (int i = 0; i < array.Length; i++)
{
int asciicode = (int)(array[i]);
ASCIIstr2 += Convert.ToString(asciicode+",");//字符串ASCIIstr2 为对应的ASCII字符串
}
Console.WriteLine(ASCIIstr2);
Console.ReadKey();
控制台输出结果为:
明细多了一个ascll值为1的控制字符,于是我查了下对应的ascll编码表:
控制字符为“soh”,于是在数据库 清除该符号,sql语句如下:
update user_table set u_name = replace (u_name,char(1),'')
因为"soh"的长度为1 ,所以清除掉1就行。