Solved

What simple function for find word in my string ? Thank you.

Posted on 2008-06-17
3
213 Views
Last Modified: 2013-11-26
What simple function for find word in my string ?

Ex. Dim tmpString As String = "View sample of a well-asked Question"

I want to check "sample" into variable tmpString is return true. I want simple function. Thank you.

ps. vb style thank.
0
Comment
Question by:sirimit
3 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 21801625
Very easy function

Call:
dim myBool as boolean
myBool = CheckField(tmpString, "sample")
    Public Function CheckField(ByVal strSentence As String, ByVal strWord As String) As Boolean
        If strSentence.IndexOf(strWord) > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

Open in new window

0
 
LVL 14

Expert Comment

by:rachitkohli
ID: 21801635
If tmpString.IndexOf("Sample",1)>0 then
msgbox "String Exist..!"
else
msgbox "not present..!!"
end if
0
 
LVL 18

Accepted Solution

by:
jcoehoorn earned 250 total points
ID: 21802422
If you care about case (will only match "sample", not "Sample" or "SAMPLE") :
    If tmpString.Contains("sample") Then
        '...
    End If

If you don't care about case (will match "sample", "Sample", and "SAMPLE"):
    If tmpString.IndexOf("sample", StringComparison.CurrentCultureIgnoreCase) > -1 Then
        '...
    End If
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question