从两个字符串之间的字符串数组中获取子字符串和char“ [英] Get substring from string array between two char " and char "
本文介绍了从两个字符串之间的字符串数组中获取子字符串和char“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从字符串数组中分隔一个子字符串,其中我的开头是Char()和我的结尾字符()。
我的代码:
I want to separate a sub string from a string array where my start Char (") and my ending Char (").
My Code:
int count = 0;
string[] arr1 = new string[reply.Length-20];
foreach (string item in list)
{
arr1[count] = item.Split(new Char[] { '"','"' });
Console.WriteLine(item);
count = count + 1;
}
请帮我将子字符串从字符串whit start char分隔到end char。
提前致谢。
我尝试过:
arr1 [count] = item.Split(new Char [] {'',''});
Please help me to separate a substring from a string whit start char to end char.
Thanks in advance.
What I have tried:
arr1[count] = item.Split(new Char[] { '"','"' });
推荐答案
拆分不这样的工作!
可能你想要的是:
Split doesn't work like that!
Possibly what you want is:
int count = 0;
foreach (string item in list)
{
string[] arr1 = item.Split(new char[] {'"'}, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in arr1)
{
Console.WriteLine(s);
count = count + 1;
}
}
问题不是很清楚。但是,String.split
返回一个数组,因此你不能将结果存储在arr1 [count]
中,因为那是一个字符串
参考。不是字符串[]
引用。同样为什么要打印item
在下一行,而不是一些拆分数据?您可能需要执行以下操作:
The issue is not really clear. However,String.split
returns an array, so you cannot store the result inarr1[count]
, since that is astring
reference. not astring[]
reference. Similarly why are you printingitem
in the next line, rather that some split data? You probably need to do something like:
foreach (string item in list)
{
string[] splits = item.Split(new Char[] { '"','"' });
// do something with the split subitems
}
目前还不清楚你想用这个代码做什么,但它可以简化。
It is not clear what you want to do with this code, but it can be simplified.
int count = 0;
string[] arr1 = new string[reply.Length-20];
foreach (string item in list)
{
arr1[count] = item.Split(new Char[] { '"','"' });
Console.WriteLine(item);
count = count + 1;
}
您对变量 count
这篇关于从两个字符串之间的字符串数组中获取子字符串和char“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文