I'm wondering if there is a way to search for an exact text match in a text box
for example
using "if textbox1.text.contains("Hello") then" works
however i only want it to search for text "Hello" and if i have 2 words like this
HelloFriend
Hello Friend
I only want it to find the word matching so the second statement Hello Friend and not HelloFriend as this doesn't match the keyword.
Is this possible?
You can make a regular expression that matches the word with word boundaries:
if Regex.IsMatch(textbox1.Text, "\b" + Regex.Escape("Hello") + "\b") Then
try to checkout
this one
or
this one
may be this one will help you :)
Related
I have this code,
If ((dataArray(i, *searchField*) = *searchValue*) Then
Which is not working. what I am trying to achieve is;
if all of search value is in any part of search field or vice versa then do X
Any help?
use the Like verb
if dataArray(i) Like searchValue
where search value begins and ends with astricks
it is a string compairson
word document may contain repeated adjacent words. can there be a vba macro code to retain single occurrence, and delete the repeat.
eg,
He is is doing well.
should change to
He is doing well.
Help would be much appreciated.
I can't try it because office.live.com doesn't seem to support wildcards, but you can try this:
In Find and Replace > Replace > check Use wildcards and in the Find what: enter "(<*>) <\1>" and click Find Next to see if that matches the two words. If it does, enter "\1" in Replace with: and click Replace All to see if everything works as expected. If it does, you can Record Macro of those steps and check the generated code.
The above expression should also find repeating numbers like a123 a123. If you don't want that, you can try this expression in the Find what:
(<[A-Za-z]{1,}>) \1[!A-Za-z]
from http://www.louiseharnbyproofreader.com/blog-the-proofreaders-parlour/proofreading-in-word-one-of-my-favourite-findreplace-strings
There is a code I am using to search for specific words in a VBA string. Currently I'm using InSTR:
tag1 = InStr(1, dish, keyword, vbTextCompare)
However the challenge is that the search is comparing strings and not words.
E.g. If I'm searching for "egg" as a keyword in a string - Eggplant Pizza, it's returning a true value.
Ideally I would simply like to search if the word "egg" exists in a string. Is there a better function I can use?
You could also use Regular Expressions to achieve this in VBA.
Looking specifically at the ^ and $ operators to force the full word match.
So in your case something like ^Egg$ as the pattern should do what you want.
See here for some good help on this:
How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops
InStr is the way to go. For finding out how many times a string is present in a text, you can use this one-line code. Here I use your example.
Debug.Print UBound(Split("Eggplant Pizza", "Egg"))
To make the code case insensitive, you can put Option Compare Text on top of your code module.
Hello great programmers in the house..
I am quite new to vb.net
I need help on how to detect if a word can be formed from another word:
here's what i mean...
TextBox1.Text="Nairaland"
TextBox2.Text= ....accepts any input
I want to be able to alert "Found!"
if something like ..."land" or "lad" or "Nail" or "Naaad".... is entered into textbox2
but "Not Found" if something like "Qeen" or "Landd" or 'Mail" is entered.
In a nutshell, I just want to be able to check if the characters in textbox2 are found in textbox1...not minding the sequence but no letter should be entered twice/trice except if it appears twice/trice
Please, help!
One way is to build a Dictionary(Char, Integer) of the character count for each character, in both textboxes. Then see if any of the characters in the second one aren't in the first or have a count greater than the first.
Basically I have created an acronym finding macro and it works well except it includes all of our reference numbers. Now unfortunately changing the search parameters won't work as many acronyms include both letters and numbers.
My idea was to compare the string, once found, and if it is in the reference number format e.g.
LetterNumberNumberLetterLetterNumberNumberNumberNumber
I will simply not include it.
I'm certain there must be a simple way of doing this and me not being able to locate it is a case of not knowing what to search for but anyway thank you in advance for the help.
Use LIKE:
'//LetterNumberNumberLetterLetterNumberNumberNumberNumber
if ucase$("A12BC3456") like "[A-Z][0-9][0-9][A-Z][A-Z][0-9][0-9][0-9][0-9]" then
msgbox "is ref no."