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) + " "; } }
public partial class Form1 : Form { // declaration of variables string text = ""; char character; int charPos = 0; string strCharPos; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // data text = textBox1.Text; // search criteria character = Convert.ToChar(textBox2.Text); // find character for (int idx = 0; idx < text.Length; idx++) { if (text[idx] == character) { charPos = idx + 1; strCharPos = strCharPos + Convert.ToString(charPos) + ", "; label1.Text = strCharPos; } } // Reset data strCharPos = ""; charPos = 0; text = ""; character = '\0'; } }
string sText = "AJAY"; string sIndex=string.Empty; for(int a=0;a<sText.Length;a++) { if(sText[a].ToString().Equal("A")) { if(sIndex != string.Empty) { sIndex += ","; } sIndex += (a+1); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)