stripping out string to get what i need

james_halliwell

Registered User.
Local time
Today, 12:26
Joined
Feb 13, 2009
Messages
211
Hi all,

first thanks for taking the time to read my post and help me out with my query :)

i have a need to strip of letters from a string but i needs to look for / as the lebght would change, below is an example of the data im working with

record 1 example ) REP/1349/999/426066/XX/9
record 2 example ) REP/UDKBS01N/1/448174/XX/

what i need to extract is
1) = 1349
2) = UDKBS01N

i need to get the information between the first / and the second / is there a funtion in access that can help me get this


many thanks
 
I like Dave's, but here is a function and a test routine, I created.

Code:
Function tryslash(rec As String) As String
   
    Dim x() As String
    
      x() = Split(rec, "/")
       tryslash = x(1)
    End Function

Test routine
Code:
Sub do_slash()
Dim x1 As String
Dim x2 As String
x1 = "REP/1349/999/426066/XX/9 "
x2 = "REP/UDKBS01N/1/448174/XX/"
Debug.Print tryslash(x1)
Debug.Print tryslash(x2)
End Sub

Result:

1349
UDKBS01N

Good luck
 
I like Dave's, but here is a function and a test routine, I created.

Code:
Function tryslash(rec As String) As String
   
    Dim x() As String
    
      x() = Split(rec, "/")
       tryslash = x(1)
    End Function

Test routine
Code:
Sub do_slash()
Dim x1 As String
Dim x2 As String
x1 = "REP/1349/999/426066/XX/9 "
x2 = "REP/UDKBS01N/1/448174/XX/"
Debug.Print tryslash(x1)
Debug.Print tryslash(x2)
End Sub

Result:

1349
UDKBS01N

Good luck


Great help guys many thanks learned split today :p!!!!!! worked like a charm :D

@jdarw

if i wanted to get the second occurrence after / to put out below

x1 = "REP/1349/999/426066/XX/9 "
x2 = "REP/UDKBS01N/1/448174/XX/"

x1 = 999
x2 = 1

how could i amend x() = Split(rec, "/") to look after the second occurance
 
figured it :cool:

Function tryslash(rec As String) As String

Dim x() As String

x() = Split(rec, "/")
tryslash = x(2)
End Function




love the function will definatly use this again
 
james. you can establish the number of splits you get with ubound.
The array is zero based, so the first element is x(0) - which is why you needed x(1) and x(2)

Dim x() As String
x() = Split(rec, "/")
maxvalue = ubound(x)


so

for index=0 to unbound(x)
msgbox(index & " " & x(index))
next
 

Users who are viewing this thread

Back
Top Bottom