Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Searching a string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
parkin_m - 12 Jun 2007 16:15 GMT
I would like to seach a string (an example of the string is
"template1-letter_head_template.doc" ) to see if it contains a "-" symbol and
then run some code if it does and run some other code if it doesnt.

I was planning on using an if statement, but i cannot find a function to
search the string - there is a replace function so i guessed there must be
one!
parkin_m - 12 Jun 2007 16:35 GMT
after i have found whether or not the string has a "-" inside it i want to
run a split function on the string so another solution to the problem might
be along the lines of:

tempA = Split(FileArray(f), "-")    'split the current file name
'IF FileArray was split then...
   With CurrentDocument                
       With ListBox1
           .AddItem tempA(0) + "   " + tempA(1)
       End With
   End With

so only insert the split file name into the list box if there was a split
array done.

Is there a way to check if the string was split?

> I would like to seach a string (an example of the string is
> "template1-letter_head_template.doc" ) to see if it contains a "-" symbol and
[quoted text clipped - 3 lines]
> search the string - there is a replace function so i guessed there must be
> one!
Jay Freedman - 12 Jun 2007 17:29 GMT
The variable tempA must be declared as a Variant datatype (although that's
the default datatype, so you can get away with not declaring it, but you
should declare it anyway to prevent bugs). A Variant can be considered to be
an array, and the UBound function will tell you the largest value of that
array's subscript. If there wasn't any "-", the entire string will be in one
element of tempA, so both the lower bound and the upper bound of tempA will
be 0. If there were one or more "-" characters, then the upper bound will be
bigger to hold all the pieces from the Split.

So this is your If statement:

  If UBound(tempA) > 0 Then   ' FileArray(f) was split

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> after i have found whether or not the string has a "-" inside it i
> want to run a split function on the string so another solution to the
[quoted text clipped - 21 lines]
>> function to search the string - there is a replace function so i
>> guessed there must be one!
Jonathan West - 12 Jun 2007 17:32 GMT
>I would like to seach a string (an example of the string is
> "template1-letter_head_template.doc" ) to see if it contains a "-" symbol
[quoted text clipped - 4 lines]
> search the string - there is a replace function so i guessed there must be
> one!

If InStr(mystring, "-") > 0 Then
   'mystring contains a hyphen
Else
   'it doesn't
End If

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.