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
Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

790 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