我们如何从字符串中过滤文本值。 [英] How can we filter text value from string.

查看:81
本文介绍了我们如何从字符串中过滤文本值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要单独的字符串  来自我的结果 string 
我的字符串变量 return value 喜欢:

string result = 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 ; // 从这里我需要2

string result = 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 ; // 从这里我需要4

string result = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 ; // 从这里我需要3





任何建议真的很感激!

解决方案

你可能先拆分字符串使用','作为分隔符(从而获得字符串数组),然后您有几个选项:例如,您可以对数组进行排序并最终获取最后一项(或者第一个,取决于实际的输入值。)


.split()将为你工作..







  string  result =  1  1  2  1  1  1  1  1  1  1 , 1  1  1  1  1  1 ; 
string strResultValue = ;
string [] strArrRestul = result.split(' );

for int intLoop = 0 ; intLoop< strarrresult.length; intloop ++)>
{
if (strArrResult [intLoop] == 2
{
strResultValue = strArrResult [intLoop];
}
}







说明:

你只是将数据存储在字符串数组中,分隔符为逗号(,),需要拆分方法

然后在字符串数组中搜索你想要的数据..


分割()中的
你可以给出结果变量中的任何分隔符。


嗨这是一个小任务,但我不能' 能够猜出它的逻辑。但我已经完成了。 





  var  finalValue = result.Replace(  )。替换(  1 ); 


I need single different string value from my resulted string.
My string variable return value like :

string result = 1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1;    //  from here I'll need  2

or  string result = 1,1,1,1,1,1,1,1,4,1,1,1,1,1,1,1;    //  from here I'll need  4

or string result = 1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1;     //  from here I'll need  3



Any suggestion really appreciate !

解决方案

You might first split the string using ',' as separator (thus obtaining an array of strings), then you have several options: for instance, you might sort the array and eventually take the last item (or the first one, depending on the actual input values).


.split() will work for you..



string result=1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1;  
string strResultValue="";
string[] strArrRestul=result.split(',');

for(int intLoop=0;intLoop<strarrresult.length;intloop++)>
{
    if(strArrResult[intLoop]=="2")
    {
        strResultValue=strArrResult[intLoop];
    }
}




Explanation:
you are just storing your data in string Array with delimiter as comma(,) with the need of split method
then in string array you are searching your desired data..

in split() you can give any delimiter which is in your result variable.


Hi Its a minor task, but I was don't able to guess its logic. But I have done.



var finalValue = result.Replace(",","").Replace("1","");


这篇关于我们如何从字符串中过滤文本值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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