如何在字符串中查找符号 [英] how to find symbol in a string
问题描述
我的字符串是
3例
字符串str = dotnet-Karnataka;
字符串str1 = -karnataka;
字符串str2 = dotnet-;
我的弦像这样
当我基于''-''
分割字符串时
我想找到地方.
dotnet排名第一,卡纳塔克邦(karnatak)排名第二.
字符串str = -karnataka;
这是第二名.
字符串str = dotnet-
这是第一名.
下次更改我的字符串时:string str = -Hyderabad;
我想找到位置,第一名或第二名
接下来我的字符串是字符串str = PHP-;
我想找到该位置的第一名或第二名.
就像我的字符串是动态更改的.
请帮忙...
谢谢.
Hi,
My string is
in 3 cases
string str=dotnet-Karnataka;
string str1= -karnataka;
string str2=dotnet-;
my string like this
when I split the string based on ''-''
I want find the place.
dotnet is first place, Karnatak is seconplace.
string str=-karnataka;
this is the second place.
string str=dotnet-
this is first place.
next time my string is changed: string str= -Hyderabad;
I want find the position, First place or second place
next my string is string str= PHP-;
I want find the postion first place or second place.
like that my string are changed dynamically.
Please Help...
Thank you.
推荐答案
你好,
您首先分割字符串.然后检查第一部分是否为Contains
``-''.
例如,如果string为" PHP-".您只是拆分了字符串并获得了两个不同的值.
在第一部分中,您将获得"PHP",第二部分中将获得-".然后确定"PHP" deoes不包含-".表示它位于第一位.
-海德巴德"也发生同样的事情.在这种情况下,海德巴德"将排在第二位.
谢谢
Hello,
You first split the string. Then Check whether the first partContains
''-'' .
For example if string is ''PHP-'' . You just split the string and got two different values .
In first part you will get ''PHP'' and second part ''-'' . then it is sure that ''PHP'' deoes not contains ''-''. means it is in first place .
same thing happens for ''-Hyderbad'' also . For that case ''Hyderbad'' will be at second position .
thanks
尝试此代码段
Try this snippet
string str = "dotnet-Karnataka";
string str1 = "-karnataka";
string str2 = "dotnet-";
string[] array = str.Split('-');
if (array.Length > 0)
{
string position1 = array[0];
string position2 = array[1];
}
这篇关于如何在字符串中查找符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!