Detect if Specific words found .Net










-1














Hello I try to find specific words of that represent a number



Ex:

- Number "One" in RichTextBox



My code :



 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim str As String = RichTextBox1.Text
Dim strarr() As String
strarr = str.Split(" "c)
For Each s As String In strarr

Dim words() As String = s.ToLower.Split(" "c, StringSplitOptions.RemoveEmptyEntries)
If words.Count(Function(w) RichTextBox2.Text.Contains(w)) > 0 Then

Label1.Text = s
Label1.Text = "Founded"
Else
Label1.Text = "not founded, if we find it, we will type it , in label1"
End If
Next

End Sub


RichTextBox2 = list of my words (1 - 5) numbers.

RichTextBox1 = which i focus on it.



The problem is when I type in RichTextBox1.text
hello i want type numbers, on

it will detect "on" as (one). This not my purpose.



explaining By picture










share|improve this question























  • I think in kinda get what you want, but just to be sure: you want to write in a box, click a button and then all the numbers found in the first box are re-written in the second box?
    – laancelot
    Nov 12 at 13:59










  • Don't use Contain(), use Equals(), maybe adding StringComparison.CurrentCultureIgnoreCase. Regex.Matches will be probably better, if you also want to know how many words you found that match the criteria and their position inside the text.
    – Jimi
    Nov 12 at 14:10










  • First, get your output straight. It will never show what was found (what is inside string s), because it gets overwritten by the text Founded. You'll see that it will output something different than you think it would.
    – AutomatedChaos
    Nov 12 at 15:13
















-1














Hello I try to find specific words of that represent a number



Ex:

- Number "One" in RichTextBox



My code :



 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim str As String = RichTextBox1.Text
Dim strarr() As String
strarr = str.Split(" "c)
For Each s As String In strarr

Dim words() As String = s.ToLower.Split(" "c, StringSplitOptions.RemoveEmptyEntries)
If words.Count(Function(w) RichTextBox2.Text.Contains(w)) > 0 Then

Label1.Text = s
Label1.Text = "Founded"
Else
Label1.Text = "not founded, if we find it, we will type it , in label1"
End If
Next

End Sub


RichTextBox2 = list of my words (1 - 5) numbers.

RichTextBox1 = which i focus on it.



The problem is when I type in RichTextBox1.text
hello i want type numbers, on

it will detect "on" as (one). This not my purpose.



explaining By picture










share|improve this question























  • I think in kinda get what you want, but just to be sure: you want to write in a box, click a button and then all the numbers found in the first box are re-written in the second box?
    – laancelot
    Nov 12 at 13:59










  • Don't use Contain(), use Equals(), maybe adding StringComparison.CurrentCultureIgnoreCase. Regex.Matches will be probably better, if you also want to know how many words you found that match the criteria and their position inside the text.
    – Jimi
    Nov 12 at 14:10










  • First, get your output straight. It will never show what was found (what is inside string s), because it gets overwritten by the text Founded. You'll see that it will output something different than you think it would.
    – AutomatedChaos
    Nov 12 at 15:13














-1












-1








-1







Hello I try to find specific words of that represent a number



Ex:

- Number "One" in RichTextBox



My code :



 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim str As String = RichTextBox1.Text
Dim strarr() As String
strarr = str.Split(" "c)
For Each s As String In strarr

Dim words() As String = s.ToLower.Split(" "c, StringSplitOptions.RemoveEmptyEntries)
If words.Count(Function(w) RichTextBox2.Text.Contains(w)) > 0 Then

Label1.Text = s
Label1.Text = "Founded"
Else
Label1.Text = "not founded, if we find it, we will type it , in label1"
End If
Next

End Sub


RichTextBox2 = list of my words (1 - 5) numbers.

RichTextBox1 = which i focus on it.



The problem is when I type in RichTextBox1.text
hello i want type numbers, on

it will detect "on" as (one). This not my purpose.



explaining By picture










share|improve this question















Hello I try to find specific words of that represent a number



Ex:

- Number "One" in RichTextBox



My code :



 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim str As String = RichTextBox1.Text
Dim strarr() As String
strarr = str.Split(" "c)
For Each s As String In strarr

Dim words() As String = s.ToLower.Split(" "c, StringSplitOptions.RemoveEmptyEntries)
If words.Count(Function(w) RichTextBox2.Text.Contains(w)) > 0 Then

Label1.Text = s
Label1.Text = "Founded"
Else
Label1.Text = "not founded, if we find it, we will type it , in label1"
End If
Next

End Sub


RichTextBox2 = list of my words (1 - 5) numbers.

RichTextBox1 = which i focus on it.



The problem is when I type in RichTextBox1.text
hello i want type numbers, on

it will detect "on" as (one). This not my purpose.



explaining By picture







.net regex vb.net visual-studio-2012






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 15:09









AutomatedChaos

5,7331740




5,7331740










asked Nov 12 at 13:03









Beginner01

95




95











  • I think in kinda get what you want, but just to be sure: you want to write in a box, click a button and then all the numbers found in the first box are re-written in the second box?
    – laancelot
    Nov 12 at 13:59










  • Don't use Contain(), use Equals(), maybe adding StringComparison.CurrentCultureIgnoreCase. Regex.Matches will be probably better, if you also want to know how many words you found that match the criteria and their position inside the text.
    – Jimi
    Nov 12 at 14:10










  • First, get your output straight. It will never show what was found (what is inside string s), because it gets overwritten by the text Founded. You'll see that it will output something different than you think it would.
    – AutomatedChaos
    Nov 12 at 15:13

















  • I think in kinda get what you want, but just to be sure: you want to write in a box, click a button and then all the numbers found in the first box are re-written in the second box?
    – laancelot
    Nov 12 at 13:59










  • Don't use Contain(), use Equals(), maybe adding StringComparison.CurrentCultureIgnoreCase. Regex.Matches will be probably better, if you also want to know how many words you found that match the criteria and their position inside the text.
    – Jimi
    Nov 12 at 14:10










  • First, get your output straight. It will never show what was found (what is inside string s), because it gets overwritten by the text Founded. You'll see that it will output something different than you think it would.
    – AutomatedChaos
    Nov 12 at 15:13
















I think in kinda get what you want, but just to be sure: you want to write in a box, click a button and then all the numbers found in the first box are re-written in the second box?
– laancelot
Nov 12 at 13:59




I think in kinda get what you want, but just to be sure: you want to write in a box, click a button and then all the numbers found in the first box are re-written in the second box?
– laancelot
Nov 12 at 13:59












Don't use Contain(), use Equals(), maybe adding StringComparison.CurrentCultureIgnoreCase. Regex.Matches will be probably better, if you also want to know how many words you found that match the criteria and their position inside the text.
– Jimi
Nov 12 at 14:10




Don't use Contain(), use Equals(), maybe adding StringComparison.CurrentCultureIgnoreCase. Regex.Matches will be probably better, if you also want to know how many words you found that match the criteria and their position inside the text.
– Jimi
Nov 12 at 14:10












First, get your output straight. It will never show what was found (what is inside string s), because it gets overwritten by the text Founded. You'll see that it will output something different than you think it would.
– AutomatedChaos
Nov 12 at 15:13





First, get your output straight. It will never show what was found (what is inside string s), because it gets overwritten by the text Founded. You'll see that it will output something different than you think it would.
– AutomatedChaos
Nov 12 at 15:13













1 Answer
1






active

oldest

votes


















0














I think this may work better:



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' first remove any previous Label1 text
Label1.Text = ""

' cleanup the RichTextBox2 text by replacing any whitespace or non-word character by a single space character
' make it all lowercase and trim off the spaces left and right
Dim keyText As String = (Regex.Replace(RichTextBox2.Text, "[sW]+", " ")).ToLower().Trim()
' next, split it into an array of keywords
Dim keyWords As String() = keyText.Split(" "c)

' get the user input and prepare it for splitting into words like we did with the RichTextBox2 text
Dim input As String = (Regex.Replace(RichTextBox1.Text, "[sW]+", " ")).ToLower().Trim()

' split the cleaned-up input string into words and check if they can be found in the keyWords array
' if we do find them, we want only list them once so collect them first in a List
Dim wordsFound As New List(Of String)
For Each word As String In input.Split(" "c)
If keyWords.Contains(word.ToLower()) Then
If Not (wordsFound.Contains(word)) Then
wordsFound.Add(word)
End If
End If
Next
' finally, add the result to the label
Label1.Text = String.Join(Environment.NewLine, wordsFound)
End Sub


demo






share|improve this answer




















  • You Are awesome, this what specific i wanted Big thanks, With Grate Solution from best Thread Ever in the world "StackoverFlow", Helped many people.
    – Beginner01
    Nov 13 at 10:37










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262791%2fdetect-if-specific-words-found-net%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think this may work better:



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' first remove any previous Label1 text
Label1.Text = ""

' cleanup the RichTextBox2 text by replacing any whitespace or non-word character by a single space character
' make it all lowercase and trim off the spaces left and right
Dim keyText As String = (Regex.Replace(RichTextBox2.Text, "[sW]+", " ")).ToLower().Trim()
' next, split it into an array of keywords
Dim keyWords As String() = keyText.Split(" "c)

' get the user input and prepare it for splitting into words like we did with the RichTextBox2 text
Dim input As String = (Regex.Replace(RichTextBox1.Text, "[sW]+", " ")).ToLower().Trim()

' split the cleaned-up input string into words and check if they can be found in the keyWords array
' if we do find them, we want only list them once so collect them first in a List
Dim wordsFound As New List(Of String)
For Each word As String In input.Split(" "c)
If keyWords.Contains(word.ToLower()) Then
If Not (wordsFound.Contains(word)) Then
wordsFound.Add(word)
End If
End If
Next
' finally, add the result to the label
Label1.Text = String.Join(Environment.NewLine, wordsFound)
End Sub


demo






share|improve this answer




















  • You Are awesome, this what specific i wanted Big thanks, With Grate Solution from best Thread Ever in the world "StackoverFlow", Helped many people.
    – Beginner01
    Nov 13 at 10:37















0














I think this may work better:



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' first remove any previous Label1 text
Label1.Text = ""

' cleanup the RichTextBox2 text by replacing any whitespace or non-word character by a single space character
' make it all lowercase and trim off the spaces left and right
Dim keyText As String = (Regex.Replace(RichTextBox2.Text, "[sW]+", " ")).ToLower().Trim()
' next, split it into an array of keywords
Dim keyWords As String() = keyText.Split(" "c)

' get the user input and prepare it for splitting into words like we did with the RichTextBox2 text
Dim input As String = (Regex.Replace(RichTextBox1.Text, "[sW]+", " ")).ToLower().Trim()

' split the cleaned-up input string into words and check if they can be found in the keyWords array
' if we do find them, we want only list them once so collect them first in a List
Dim wordsFound As New List(Of String)
For Each word As String In input.Split(" "c)
If keyWords.Contains(word.ToLower()) Then
If Not (wordsFound.Contains(word)) Then
wordsFound.Add(word)
End If
End If
Next
' finally, add the result to the label
Label1.Text = String.Join(Environment.NewLine, wordsFound)
End Sub


demo






share|improve this answer




















  • You Are awesome, this what specific i wanted Big thanks, With Grate Solution from best Thread Ever in the world "StackoverFlow", Helped many people.
    – Beginner01
    Nov 13 at 10:37













0












0








0






I think this may work better:



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' first remove any previous Label1 text
Label1.Text = ""

' cleanup the RichTextBox2 text by replacing any whitespace or non-word character by a single space character
' make it all lowercase and trim off the spaces left and right
Dim keyText As String = (Regex.Replace(RichTextBox2.Text, "[sW]+", " ")).ToLower().Trim()
' next, split it into an array of keywords
Dim keyWords As String() = keyText.Split(" "c)

' get the user input and prepare it for splitting into words like we did with the RichTextBox2 text
Dim input As String = (Regex.Replace(RichTextBox1.Text, "[sW]+", " ")).ToLower().Trim()

' split the cleaned-up input string into words and check if they can be found in the keyWords array
' if we do find them, we want only list them once so collect them first in a List
Dim wordsFound As New List(Of String)
For Each word As String In input.Split(" "c)
If keyWords.Contains(word.ToLower()) Then
If Not (wordsFound.Contains(word)) Then
wordsFound.Add(word)
End If
End If
Next
' finally, add the result to the label
Label1.Text = String.Join(Environment.NewLine, wordsFound)
End Sub


demo






share|improve this answer












I think this may work better:



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' first remove any previous Label1 text
Label1.Text = ""

' cleanup the RichTextBox2 text by replacing any whitespace or non-word character by a single space character
' make it all lowercase and trim off the spaces left and right
Dim keyText As String = (Regex.Replace(RichTextBox2.Text, "[sW]+", " ")).ToLower().Trim()
' next, split it into an array of keywords
Dim keyWords As String() = keyText.Split(" "c)

' get the user input and prepare it for splitting into words like we did with the RichTextBox2 text
Dim input As String = (Regex.Replace(RichTextBox1.Text, "[sW]+", " ")).ToLower().Trim()

' split the cleaned-up input string into words and check if they can be found in the keyWords array
' if we do find them, we want only list them once so collect them first in a List
Dim wordsFound As New List(Of String)
For Each word As String In input.Split(" "c)
If keyWords.Contains(word.ToLower()) Then
If Not (wordsFound.Contains(word)) Then
wordsFound.Add(word)
End If
End If
Next
' finally, add the result to the label
Label1.Text = String.Join(Environment.NewLine, wordsFound)
End Sub


demo







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 16:15









Theo

3,7651520




3,7651520











  • You Are awesome, this what specific i wanted Big thanks, With Grate Solution from best Thread Ever in the world "StackoverFlow", Helped many people.
    – Beginner01
    Nov 13 at 10:37
















  • You Are awesome, this what specific i wanted Big thanks, With Grate Solution from best Thread Ever in the world "StackoverFlow", Helped many people.
    – Beginner01
    Nov 13 at 10:37















You Are awesome, this what specific i wanted Big thanks, With Grate Solution from best Thread Ever in the world "StackoverFlow", Helped many people.
– Beginner01
Nov 13 at 10:37




You Are awesome, this what specific i wanted Big thanks, With Grate Solution from best Thread Ever in the world "StackoverFlow", Helped many people.
– Beginner01
Nov 13 at 10:37

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262791%2fdetect-if-specific-words-found-net%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto