获取字符串的特定部分 [英] Getting Specific parts of a string
问题描述
大家好,我是CodeProject的新手,这是我的第一个问题,请忽略错误
我有一个像
< pre lang =c#> string line = abc def ghi jkl;
我正在使用
拆分(' ');
基于空格分割字符串,我成功完成了此操作out put就像是
abc< br />
def< br />
ghi< br />
jkl
我的问题是,如何在分割后获取此字符串的某些特定部分,而不是像我的情况那样得到所有部分。我希望输出类似于
abc< br />
jkl< br />
abc
def
ghi
jkl
array =< pre lang = vb > abc
def
ghi
jkl < / pre >
你已经输出正确所以制作一个循环
string aa ='' ;
for(int i = 0; i< array.length; i ++)>
{
if(array [i] = =abc或array [i] ==jkl)
string aa = array [i] +','
}
所以在aa你得到字符串
string [] array = line.split( ' ');
console.writeline(array [ 0 ]);
console.writeline(array [ 3 ]);
Hi all, I am new to CodeProject and this is my first question please ignore mistakes
I had a string like
string line="abc def ghi jkl";
I am usingSplit(' ');to split the string on the basis of space and I succeed to do this and out put is like
abc<br /> def<br /> ghi<br /> jkl
My question is that how I can get some specific parts of this string after splitting instead of getting all as in my case. I want the output something like that
abc <br /> jkl<br />解决方案abc def ghi jkl
array=<pre lang="vb">abc def ghi jkl</pre>
you already have output right so make one loop
string aa='';
for(int i=0;i<array.length;i++)>
{
if(array[i]=="abc" or array[i]=="jkl")
string aa=array[i]+ ','
}
so in aa you get string
string[] array = line.split(' '); console.writeline(array[0]); console.writeline(array[3]);
这篇关于获取字符串的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!