• VB.net Question
    3 replies, posted
Ok, so i got this program i have to make, i need to find a Character(Textbox1.text) in a 3 string(textbox2.text multiline) and print to a label the number of time that the Character is in the string. Example : Char = a String = I have no car I am poor I Suck at Programming Label1.text = Phrase 1 A = 2 Phrase 2 A = 1 Phrase 3 A = 2 How do i do this???
It is not likely the best way of doing it. But this will work. [CODE]String.Split("a").Length - 1[/CODE]
[QUOTE=Go101;33825442]It is not likely the best way of doing it. But this will work. [CODE]String.Split("a").Length - 1[/CODE][/QUOTE] Even though I would never encourage anyone to do it this way, I somehow like the idea :v: Just iterate over the string's characters with a for(each) loop and increase a counter for every hit. I can't give you the exact VB code because only do C#, but there it is along the lines of [code] string myString = "I have no car"; char myCharacter = 'a'; int myCounter = 0; foreach (char c in myString) if (c == myCharacter) myCounter++; [/code]
[QUOTE=Go101;33825442]It is not likely the best way of doing it. But this will work. [CODE]String.Split("a").Length - 1[/CODE][/QUOTE] That's actually quite a novel idea, I wouldn't have thought of doing it like that :v: Have a programming king for ingenuity.
Sorry, you need to Log In to post a reply to this thread.