首页 > 编程知识 正文

html半角空格怎么输入,html 显示空格

时间:2023-05-03 20:19:07 阅读:242440 作者:2427

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;        }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。