|
-
May 2nd, 2007, 03:59 AM
#1
Thread Starter
Member
[RESOLVED] obtain from a string
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
----------------------------------------
never drive faster than your angel can fly
----------------------------------------
-
May 2nd, 2007, 04:09 AM
#2
Re: obtain from a string
You mean get a certain part of a string?
-
May 2nd, 2007, 04:12 AM
#3
Re: obtain from 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:
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)
StartPos is the position of the last "\" symbol, found using "InStrRev".
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".
Last edited by NickThissen; May 2nd, 2007 at 04:17 AM.
-
May 2nd, 2007, 04:15 AM
#4
Thread Starter
Member
Re: obtain from a string
yes.
i only want to obtain pri004 from that string or the content from "pri" to the character "_"
----------------------------------------
never drive faster than your angel can fly
----------------------------------------
-
May 2nd, 2007, 04:20 AM
#5
Re: obtain from a string
vb Code:
Dim str As String
str = "C:\Documents and Settings\nf\Desktop\pri004_02052007.xml"
Text1.Text = Mid$(str, 38, 6)
-
May 2nd, 2007, 04:27 AM
#6
Re: obtain from a string
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
-
May 2nd, 2007, 04:33 AM
#7
Fanatic Member
Re: obtain from a string
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)
- Use the thread tools to Mark your Thread as Resolved when your question is answered.
- Please Rate my answers if they where helpful.
-
May 2nd, 2007, 04:42 AM
#8
Thread Starter
Member
Re: obtain from a string
thx robbedaya...it was that I was needing.
thx also all who answered me.
thx community
----------------------------------------
never drive faster than your angel can fly
----------------------------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|