|
-
Dec 7th, 2005, 12:14 AM
#1
Thread Starter
Addicted Member
[RESOLVED] splitting up a string
Ill tell you what i need it for first. It is a simple chat that looks for a command in text that is sent. for instance "/msg"
Now each string will consist of this ( User: /msg this is a message bla bla bla )
what i need to do is split this up so that it will put the following into seperate string:
User
Command ( /msg for example )
and what follows /msg
i've tried using the split function but i dont know how to make everything that follows /msg a complete string instead after each space it is broken up
heres the code for that which wont work for me
a = Split(teststring)
For i = LBound(a) To UBound(a)
MsgBox a(i)
Next
End
i need something with Len correct?
Last edited by Coolone770; Dec 7th, 2005 at 12:17 AM.
-
Dec 7th, 2005, 12:22 AM
#2
Re: splitting up a string
You just have to figure out how to parse it. Try this out:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim str$
Dim a$()
Dim b As Integer
str = "User: /msg this is a message bla bla bla"
a() = Split(str, ": ")
b = InStr(a(1), " ")
MsgBox "User: " & a(0) & vbCrLf & _
Left(a(1), b) & vbCrLf & "Says: " & Mid(a(1), b + 1) & vbCrLf
End Sub
-
Dec 7th, 2005, 12:25 AM
#3
Thread Starter
Addicted Member
Re: splitting up a string
works perfect!
your the best, thanks
-
Dec 7th, 2005, 12:26 AM
#4
Re: [RESOLVED] splitting up a string
Glad that you are satisfied.
-
Dec 7th, 2005, 12:36 AM
#5
Thread Starter
Addicted Member
Re: [RESOLVED] splitting up a string
is there a way to verify the string is in this format before breaking it down so it doesnt return any errors?
-
Dec 7th, 2005, 12:41 AM
#6
Re: [RESOLVED] splitting up a string
VB Code:
Private Sub Form_Load()
Dim str$
Dim a$()
Dim b As Integer
str = "User: /msg this is a message bla bla bla"
a() = Split(str, ": ")
b = InStr(a(1), " ")
MsgBox "User: " & a(0) & vbCrLf & _
Left(a(1), b) & vbCrLf & "Says: " & Mid(a(1), b + 1) & vbCrLf
End Sub
You can say
VB Code:
if Instr(str,":") > 0 then ' make sure there's a ":"
then, as long as there's a space after that, you're cool.
If not, you could do the same thing, but I think you'd find a space anyways.
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
|