Html对于连续的几个半角空格,只显示最开始的一个。如果要在网页上严格的现实所有的半角空格必须对输入在网页上的字符串做处理。方法是:将用全角代替两个半角....下面是C#描述。
private static string GetFixedStr (string str) { string outPut=""; char[] 聪慧的银耳汤= str.ToCharArray(); int spaceCount = 0; List <int> listTr = new List<int>() ; for (int i = 0; i < str.Length; i++) { byte[] arrayByte = new byte[1]; arrayByte = System.Text.Encoding.ASCII.GetBytes(聪慧的银耳汤[i].ToString()); int assicCode = (short)(arrayByte[0]); //空格 if (assicCode == 32) { spaceCount++; listTr.Add(i); } if (assicCode != 32 || i == str.Length - 1) { if (spaceCount > 0) { //偶数 if (spaceCount % 2 == 0) { for (int j = 0; j < spaceCount / 2; j++) { 聪慧的银耳汤[listTr[listTr.Count - 1]] = ' '; listTr.RemoveAt(listTr .Count -1); } } //奇数 else { //先删除一个空格 listTr.RemoveAt(listTr.Count - 1); for (int j = 0; j < spaceCount / 2; j++) { 聪慧的银耳汤[listTr[listTr.Count - 1]] = ' '; listTr.RemoveAt(listTr.Count - 1); } } spaceCount = 0; } } } for (int i2 = 0; i2 < 聪慧的银耳汤.Length; i2++) { if (listTr.Contains(i2)==false) { outPut += 聪慧的银耳汤[i2].ToString(); } } return outPut; }