locating character position in a text string

G

GeoVron

want to locate a character position in a text string, i.e. want to know what
position it is in the string ex// "1234 /CAIU456789" / would be the 7th
position. Is there
a Built In Function for this?
 
A

Arvin Meyer [MVP]

GeoVron said:
want to locate a character position in a text string, i.e. want to know
what
position it is in the string ex// "1234 /CAIU456789" / would be the 7th
position. Is there
a Built In Function for this?

This will locate the position of a character in a string. If the character
exists more than once, it will give the position of the last occurrence.

Function RightInstr(strString As String, strCharacter As String)
'********************************************************************
' Name: RightInstr
' Purpose: Counts the position of the last occurence of a character in a
string
' Author: Arvin Meyer
' Date: 02/03/97
' Comment:
'********************************************************************
On Error GoTo Err_RightInstr

Dim intPos As Integer
intPos = Len(strString)

Do While intPos > 0
If InStr(intPos, strString, strCharacter) <> 0 Then
RightInstr = intPos
Exit Do
Else
intPos = intPos - 1
End If
Loop

Exit_RightInstr:
Exit Function

Err_RightInstr:
MsgBox Err.Description
Resume Exit_RightInstr

End Function
 
J

John W. Vinson

want to locate a character position in a text string, i.e. want to know what
position it is in the string ex// "1234 /CAIU456789" / would be the 7th
position. Is there
a Built In Function for this?

Yes: it's called InStr.

Instr("1234 /CAIU456789". "/")

will return an integer 7.
 
S

sergio.stecca

want to locate a character position in a text string, i.e. want to know what
position it is in the string ex// "1234  /CAIU456789"  / would be the 7th
position.   Is there
a Built In Function for this?

You can use the following
dim Posixx
Posixx = InStr(string, Characters)

[string] could be "1234 /CAIU456789" or a field name where the string
is in
[Characters] could be "/" or a field name where the "/" is in
[Posixx] is the position number where "/" is, i this example is 7
When the Characters searched are not present into string,
the system put a "0" into Posixx

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top