Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching a string

Status
Not open for further replies.

WynneSMI

Programmer
Dec 16, 2002
76
US
I have a string and I'm trying to check it to see if the last character is a '\' or not. How do I do that? Thanks.
 
First of all you can use the instr function for searching a string, although I believe that the function:
mid(StringName,len(stringName-1),1)
that will give you the last char will be more helpful for you..
 
Now I get this error on that line of code:

Compiler error:

Variable required - can't assign to this expression

Any ideas? Thanks.
 
Sounds like you are using the StringName variable that he gave you in his example without declaring it.

You could use the Mid() function or the Right() function. Use the latter as:

Right(strName,1)

to isolate the last character on the right of the string.

Good luck
 
Instead of
mid(StringName,len(stringName-1),1)
Try
mid(Stringname,len(Stringname)-1,1)

Cheers
 
I think we're misunderstanding his problem!
All of these are functions. However, they all need to assign there returned value to a pre-declared variable.
If you haven't defined a variable then you'd get the error
warning. As assuming you're searching the last character of str_input, try:

Dim str_return As String

str_return = Right(str_input, "\", 1)

If (str_return = "\") Then
<Do something.>
Else
<Do something else.>
End If
 
You can use a function as an IF condition as in:

If Right(strInput,1) = &quot;/&quot; Then
<Do something>
Else
<Do something else>
End If

If you are looking for the last character of a string, Right() is the function to use. It doesn't need to get any more complicated than that.
BlackburnKL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top