text manipulation function help request

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

greetings

i have a text manipulation question. I have strings with letter, numbers,
commas and spaces. Commas are always followed by a space. I need a function
to 'extract' the part of the string to the right of the last comma, if there
is one! so:

asg, iiet66 n gives iiet66 n (no leading space)
asg, dd, 3 4 gives 3 4 (no leading space)
asg gives asg

any suggestions welcome!
 
Victoria said:
greetings

i have a text manipulation question. I have strings with letter,
numbers, commas and spaces. Commas are always followed by a space.
I need a function to 'extract' the part of the string to the right of
the last comma, if there is one! so:

asg, iiet66 n gives iiet66 n (no leading space)
asg, dd, 3 4 gives 3 4 (no leading space)
asg gives asg

any suggestions welcome!

How about:

LTrim(Mid([OriginalString], InStrRev([OriginalString], ", ") + 1))

Note that, if there is more than one space after the comma, it will drop
them all. If that's not what you want, it's probably easiest to write a
user-defined function for the purpose.
 
Victoria,

Here is a function that will return what you are wanting:

Function ReturnValOnly(StringVal As String)
Dim strSearchVal As String
Dim bytCharLoc As Byte
Dim bytStartSearch As Byte
bytStartSearch = 0
strSearchVal = ","
'look for a comma in the string
bytCharLoc = InStr(1, StringVal, strSearchVal)
'two checks for the value of the variable "bytCharLoc"
' are require due to the fact that there may not
' be a comma in the string, if there is then a second
' check of this variable within the loop is required
If bytCharLoc > 0 Then
'find the last comma in the string
FindNext:
If bytCharLoc > 0 Then
bytStartSearch = bytCharLoc + 1
bytCharLoc = InStr(bytStartSearch, StringVal, strSearchVal)
GoTo FindNext
End If
End If
ReturnValOnly = Right(StringVal, Len(StringVal) - bytStartSearch)
End Function

You would call the function with the following line, passing in the string
value to be used to return your value:

ReturnValOnly(strValToBeRead)
 
I need a function
to 'extract' the part of the string to the right of the last comma, if
there is one! so:

v = split(myString, ", ")

r = v(ubound(v, 1))


Hope that helps


Tim F
 
Victoria,

The responses to your posting just prove that there are many ways to
accomplish the same thing when using Access.

Dirk's solution is most likely the most straight forward. I never cease to
be impressed with his work.
 
Back
Top