C#中的字符串长度是1 +实际字符串长度值,我疯了 [英] String length in C# is 1+real string length value, I'm going crazy

查看:230
本文介绍了C#中的字符串长度是1 +实际字符串长度值,我疯了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



这是我第一次看到这种行为。使用这个简单的代码



  string  strInput =   1100100100001111110110101010001000100001011010001100001000110100;  int  strlen = strInput.Length; 







和一串64个字符,我的长度为65.



i获得实际长度+1,每个字符串放在strInput !!中。我该如何解决这个问题?

提前致谢!



我尝试了什么:



更改操作系统中的语言设置,但没有结果

解决方案

您似乎有一个不可打印的字符字符串的开头: e280ad



这是从左到右覆盖字符:

Unicode字符'LEFT-TO-RIGHT OVERRIDE'(U + 202D) [ ^ ]


  string  strInput =   1100100100001111110110101010001000100001011010001100001000110100; 
int len1 = strInput.Length; // 65
string final = ;
for int i = 0 ; i < strInput.Length; i ++)
{
char c = strInput [i]; // strInput [0] - >''(8237)
if char .IsDigit(c))
final + = strInput [i] .ToString();

}
int len2 = final.Length; // 64





'1100 ....'之前的第一个字符是Unicode,它是不可打印的字符,其unicode值为8237

Unicode Decimal Code& amp;#8237; [ ^ ]


Hello,

this is the 1st time i see this behavior. With this simple code

string strInput = "‭1100100100001111110110101010001000100001011010001100001000110100";            int strlen = strInput.Length;




and a string of 64 chars i get length of 65.

i get real length +1 with every string i put in strInput!!. How can i solve this?
Thanks in advance!

What I have tried:

to change language settings in OS but with no result

解决方案

You appear to have a non-printable character at the start of your string: e280ad

This is the "Left-to-right override" character:
Unicode Character 'LEFT-TO-RIGHT OVERRIDE' (U+202D)[^]


string strInput = "‭1100100100001111110110101010001000100001011010001100001000110100";
          int len1 = strInput.Length; // 65
          string final = "";
          for (int i = 0; i < strInput.Length; i++)
          {
              char c = strInput[i]; //strInput[0]->'' (8237)
              if (char.IsDigit(c))
                  final += strInput[i].ToString();

          }
          int len2 = final.Length;  //64



The very first char before '1100....' is an Unicode which is non printable char whose unicode value is 8237
Unicode Decimal Code &amp;#8237;[^]


这篇关于C#中的字符串长度是1 +实际字符串长度值,我疯了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆