Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-17
3
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:
Joel Coehoorn earned 1000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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