Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ppl! How can I make my application find a word after a word? I have done this in VB.NET with this code:

Dim str As String = TextBox1.Text$.Replace(" ", vbNullString)
        TextBox1.Text = TextBox2.Text$.Substring(TextBox2.Text$.IndexOf(str) + Val(str.Length + 1)).Split(" ")(0)


But, when I use VB.NET to C# converter I get this code:

string str = textBox1.Text.Replace(" ", null);
            textBox1.Text == textBox2.Text.Substring(textBox2.Text.IndexOf(str) + Conversion.Val(str.Length + 1)).Split(" ")(0);


I get errors, such as 'Conversion' does not exist in the current context. Can anyone help?

What I have tried:

string str = textBox1.Text.Replace(" ", null);
            textBox1.Text == textBox2.Text.Substring(textBox2.Text.IndexOf(str) + Conversion.Val(str.Length + 1)).Split(" ")(0);
Posted
Updated 25-Jul-17 2:57am

That's the fault of your VB code: why are you doing this at all:
Val(str.Length + 1)
Val converts a string to a number, so you take two numbers, add them together, convert them to a string, then convert them back to a number...

Try:
string str = textBox1.Text.Replace(" ", null);
textBox1.Text = textBox2.Text.Substring(textBox2.Text.IndexOf(str) + str.Length + 1).Split(" ")[0];
 
Share this answer
 
Hi,

Your c# code.

C#
string str = textBox1.Text.Replace(" ", null);
string[] aryDados  = textBox2.Text.Substring(textBox2.Text.IndexOf(str) + (str.Length + 1)).Split(' ');
textBox1.Text = aryDados[0];
 
Share this answer
 
You can do it like this:

string text = "one word right";
var after = text.Split(new string[] { "word" }, StringSplitOptions.None);
if (after.Length > 1)
{
    string right = after[1].Trim(' ');
    string firstWordAfter = right.IndexOf(" ") > -1
                 ? right.Substring(0, right.IndexOf(" "))
                 : right;
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900