我有一个字符串代码=“\ 0 \ u0001 \ 0 \ 0 \ 0 ???? \ u0001 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ u000f \ u0001 \ 0 \ 0 \ 0 \ u001f \ U0001 \ ABC01 \ 0 \ 0 \ 0 \ u001f \ 0 \ 0 \ 0 \ U0002 \ DEF \ 01 \ 0 \ 0 \ 0 \ u001f \ 0 \ 0 \ 0 \ U0003 \\ GHI01 \ 0 \ 0 \ 0 \ u001f \ 0 \ 0 \ 0"
我需要检索……
注意:code.IndexOf(“\ u000”+ i)不起作用,因为你不能将整数转换为字符串,而IndexOf所做的是在字符串中找到该字符的数字位置,而不是你应该尝试code.IndexOf (“\ u000”)+ i你在哪里这是向位置添加值的正确方法(IndexOf返回的值),如果这是你的目标 你不能使用反斜杠\,因为它是一个转义序列字符\ n \ r \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n要读的字符
注意:code.IndexOf(“\ u000”+ i)不起作用,因为你不能将整数转换为字符串,而IndexOf所做的是在字符串中找到该字符的数字位置,而不是你应该尝试code.IndexOf (“\ u000”)+ i你在哪里这是向位置添加值的正确方法(IndexOf返回的值),如果这是你的目标
你不能使用反斜杠\,因为它是一个转义序列字符\ n \ r \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n要读的字符
在任何情况下,我都创建了这个方法来提取文本字符串的大写字母
public List<string> GetUpperLetters(string input) { List<string> result = new List<string>(); int index_0 = 0; string accum = string.Empty; //Convert string input to char collection //and walk it one by one foreach (char c in input.ToCharArray()) { if(char.IsLetter(c) && char.IsUpper(c)) { accum += c; index_0++; if(index_0 == 3) { index_0 = 0; result.Add(accum); accum = string.Empty; } } } return result; }
哪里
GetUpperLetters(代码)[索引从零到n]
string code= "\0\u0001\0\0\0????\u0001\0\0\0\0\0\0\0\u000f\u0001\0\0\0\u001f\u0001\\ABC01\0\0\0\u001f\0\0\0\u0002\DEF\01\0\0\0\u001f\0\0\0\u0003\\\GHI01\0\0\0\u001f\0\0\0"; GetUpperLetters(code)[0] returns ABC GetUpperLetters(code)[1] returns DEF GetUpperLetters(code)[2] returns GHI
非常感谢大家的建议答案。 @Immersive的那个人工作了! 要做的更改是字符串代码= @“\ 0 \ u0001 \ 0 \ 0 \ 0 ???? \ u0001 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ u000f \ u0001 \ 0 \ 0 \ 0 \ u001f \ U0001 \ ABC01 \ 0 \ 0 \ 0 \ u001f \ 0 \ 0 \ 0 \ U0002 \ DEF \ 01 \ 0 \ 0 \ 0 \ u001f \ 0 \ 0 \ 0 \ U0003 \\ GHI01 \ 0 \ 0 \ 0 \ u001f \ 0 \ 0 \ 0" 和
code.Substring((code.IndexOf(@“\ u000”+ i)+(@“\ u000”+ i).Length),code.IndexOf(@“\ u000”+(i + 1)) - 代码。 IndexOf(@“\ u000”+ i) - (@“\ u000”+ i).Length));