it want to obtain from a string the next result: pri004
The string:
C:\Documents and Settings\nf\Desktop\pri004_02052007.xml
how can i do it....??
thx
Printable View
it want to obtain from a string the next result: pri004
The string:
C:\Documents and Settings\nf\Desktop\pri004_02052007.xml
how can i do it....??
thx
You mean get a certain part of a string?
Is it just this string you want, or do you want to do it with other strings aswell?
You will probably need to know a few things like, is everything in front of "pri004" always the same, is the length of substring "pri004" always the same etc...
if you know that you can use things like Mid$(), InStr() etc to get it.
For example, you could use:
StartPos is the position of the last "\" symbol, found using "InStrRev".Code:Dim myvar As String
Dim mystring As String
Dim StartPos As Integer
mystring = "C:\Documents and Settings\nf\Desktop\pri004_02052007.xml"
StartPos = InStrRev(mystring, "\")
myvar = Mid$(mystring, StartPos + 1, 6)
Then the Mid$() fucntion finds the part of the string that starts 1 position after StartPos (StartPos + 1) and is 6 characters long, which in this case is "pri004".
yes.
i only want to obtain pri004 from that string or the content from "pri" to the character "_"
vb Code:
Dim str As String str = "C:\Documents and Settings\nf\Desktop\pri004_02052007.xml" Text1.Text = Mid$(str, 38, 6)
This would be another way...
You copy and paste the path into text1 and then click this button. And if the path contains "pri" then in text2 it will show "pri" & the 3 digits after it.
vb Code:
Private Sub Command1_Click() Dim str As String str = Text1.Text If InStr(1, str, "pri") > 0 Then Text2.Text = Mid$(str, 38, 6) End If End Sub
vb Code:
Private Sub Command1_Click() Dim str As String Dim i1 as integer, i2 as integer, i3 as integer str = Text1.Text i1 = InStr(1, str, "pri") 'location of pri in the string i2 = InStr(i1, str, "_") 'location of the first _ in the string after "pri" i3 = i2 - i1 -1 'length of the string you want to get If i1 > 0 And i2 > 0 And i3 > 0 Then Text2.Text = Mid$(str, i1, i3) End If End Sub
(Note that this is free-hand coding, it was not tested, it could contain errors, but it should get you on the way)
thx robbedaya...it was that I was needing.
thx also all who answered me.
thx community