Solved

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

Posted on 2008-06-17
3
209 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now