• Looking for word in a String?
    9 replies, posted
Hello, do any of you know how you could find a particular word in VB.NET (I know, sucks, hope to go to C# soon) in a string? e.g how to find DG2 in AJAJFHA[b]DG2[/b]VSUCJA? Thanks, any help appreciated.
Do you mean find if it exists? Or find the position? to find whether it contains the string passeed String.Contains("DG2") Return type: boolean to find the index of the string passed String.IndexOf("DG2") Return type: int
-snip- His is better. :)
[QUOTE=efeX;18105666]Do you mean find if it exists? Or find the position? to find whether it contains the string passeed String.Contains("DG2") Return type: boolean to find the index of the string passed String.IndexOf("DG2") Return type: int[/QUOTE] String.Contains seems to be the one i'm looking for. Thanks alot.
I have just tried that now and it dosen't do what I want correctly :( - I wasn't that specific in the OP (sorry), What I meant is, lets say you had 526419, and 52 = a, 64 = b, and 19 = c. Do you know how I would then make that string into abc? Think of it as like a binary converter, trying to convert 0100100001101001 back into Hi
Use a regular expression?
[QUOTE=ConTron123;18110359]I have just tried that now and it dosen't do what I want correctly :( - I wasn't that specific in the OP (sorry), What I meant is, lets say you had 526419, and 52 = a, 64 = b, and 19 = c. Do you know how I would then make that string into abc? Think of it as like a binary converter, trying to convert 0100100001101001 back into Hi[/QUOTE] Binary conversion and moving your string into parts are two way different concepts. What exactly do you mean by splitting that string? Do you want to search for the predefined letters, etc? You may want to look at the Mid function in VB.
[QUOTE=andersonmat;18111357]Binary conversion and moving your string into parts are two way different concepts. What exactly do you mean by splitting that string? Do you want to search for the predefined letters, etc? You may want to look at the Mid function in VB.[/QUOTE] I want to search for the predefined letters and then replace them (e.g 5216 becomes AB, 52 = A, 16 = B)
[QUOTE=ConTron123;18111968]I want to search for the predefined letters and then replace them (e.g 5216 becomes AB, 52 = A, 16 = B)[/QUOTE] Make a HashTable containing all the conversions you want, then loop through the string and replace each instance of the Key (52, 16, etc...) with the corresponding value (A, B, etc...). My VB is a bit rusty, so bear with me [cpp] Sub ConvertString(ByRef conversionString) Dim conversions as new HashTable() conversions.Add("52", 'A') conversions.Add("16", 'B') For Each conversion In conversions conversionString = conversionString.Replace(conversion.Key, conversion.Value) Next conversion End Sub [/cpp]
[QUOTE=t0rento;18121457]Make a HashTable containing all the conversions you want, then loop through the string and replace each instance of the Key (52, 16, etc...) with the corresponding value (A, B, etc...). My VB is a bit rusty, so bear with me [cpp] Sub ConvertString(ByRef conversionString) Dim conversions as new HashTable() conversions.Add("52", 'A') conversions.Add("16", 'B') For Each conversion In conversions conversionString = conversionString.Replace(conversion.Key, conversion.Value) Next conversion End Sub [/cpp][/QUOTE] If that works I love you. Edit: Thanks, what I was looking for But is there anyway to fix how if I enter [b]pyro[/b] to [b]b7a28ld6o4z[/b] using the conversions.Add method becomes [b]pyldz4z[/b] Is there any way to fix that? The conversions.Add are all correct, it should become pyro again but it's giving me this EDIT again: Nvm, fixed it.
Sorry, you need to Log In to post a reply to this thread.