本文介绍了查找字符串中字符的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我有一个问题,我们如何才能找出字符在字符串值中的位置.
就像我在文本框中键入arun,然后在下一个文本框中键入"u".
然后单击buttn,它将在"arun"中显示"u"的位置.
谢谢您的宝贵建议,但仍然存在一个问题,
如果角色本身是重复的,wt会做,我们需要每次都找出它的位置.比如``ajay''中``a''的位置在索引0和2处.wt我应该找到两个position

hello guys.
i have a question, how can we find out position of a character in a string value.
like i type arun in a textbox, then i type ''u'' in next textbox.
then on the click of buttn it displays the position of ''u'' in ''arun''.
thanx for ur valuable suggestion ,but there is still a problum,
wt will we do if a character is repetation itself and we need to find out find out it position everytime.like position of ''a ''in ''ajay'' is at index 0 and 2 .wt should i do to find both positions

推荐答案

String myName=TextBox1.Text;
String findCharacter=TextBox2.Text;

Int myCharacterIsAt=myName.IndexOf(findCharacter,1);
//It will return the index staring from zero.
// ie. in case of "u" you will get 2 as index

//Display the result
TextBox3.Text=myCharacterIsAt + 1; // Will return 3 in your example


int i=0;
String myName=TextBox1.Text;
String findCharacter=TextBox2.Text;

for(i=0;i<myname.length;i++)>
{
 if(myName[i]==findCharacter)
 {
  TextBox3.Text=(i+1) + " ";
 }
}



这篇关于查找字符串中字符的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 16:15
查看更多