Link to home
Start Free TrialLog in
Avatar of Nightma12
Nightma12

asked on

Pulling Apart A String into diferent strings (and some integers) (VB6)

Hello,

my program reads a text file outputted by another program and places it into a string i need to split this string up into seperate strings how would this be done?

One thing that the string may contain is

[02:10:13] Host: DrkAgnt is a game moderator.

this is basically what someone is saying in game what i need to split it up into is..

Time
nick
1st word
2nd word
3rd word
4th word
rest of there message
chat mode

so the above would be split into the following

Time = 02:10:13
nick = Host
1st word = DrkAgnt
2nd word = is
3rd word = a
4th word = game
rest of text = moderator.
chat mode = ALL

you can tell what chat mode would be by the following

Page would be

[00:37:41] [Page] ooops21: OK

(note the [Page] part of it)

Team would be

[00:37:41] [Team] ooops21: OK


and All would be

[00:37:41] ooops21: OK

it cane also comes out like the following...

[02:05:41] Id  Name           Score Side      Ping      Address               Kbits/s Time
[02:05:41]   1 iso8859        267   GDI      135      68.113.231.76;1068    19      000.06.04
[02:05:41]   2 Weslox2        628   NOD      163      24.76.23.247;1612     23      000.04.49
[02:05:41]   3 aaa11888       12    GDI      118      67.127.103.121;30     19      000.01.41
[02:05:41]   4 hex29          0     NOD      109      24.215.131.47;2647    16      000.01.34

this will come one string at a time (im using a For t = 1 To foundcount        Next loop )

i need this split into the following

Private Type player_info(127)
name As String
Score As Integer
Side As String
Ping As Integer
IP As String
Port As Integer
kb As Integer
hour As Integer (the 3 digits under time)
minute As Integer (the next 2)
seconds As Integer (the last 2)
End Type

i need the id to be same as the array number if there is no id for a certain array number it needs to be blank

sometimes it could also come out like...

[02:07:47] Westwood Online mode active since 4/11/2004 - 14:45:51 PM
[02:07:47] Gameplay in progress
[02:07:47]      Map : C&C_Canyon.mix
[02:07:47]     Time : 0.28.23
[02:07:47]      Fps : 60
[02:07:47]      GDI : 1/32 players      1059 points
[02:07:47]      NOD : 2/32 players      2618 points

or

[02:07:47] GameSpy mode active since 4/11/2004 - 14:45:51 PM
[02:07:47] Gameplay in progress
[02:07:47]      Map : C&C_Canyon.mix
[02:07:47]     Time : 0.28.23
[02:07:47]      Fps : 60
[02:07:47]      GDI : 1/32 players      1059 points
[02:07:47]      NOD : 2/32 players      2618 points

i need this to be done into the following

Private type game
map As String
Time as String
fps as integer
gdip As Integer    (number of player on GDI)
gdiof As Integer   (maximum number of plauers on gdi)
nodp As Integer    (number of players on nod)
nodof As Integer   (maximum number of players on nod)
gamer As Boolean (True if it comes out as [02:07:47] Gameplay in progress False if anything else
gdipo As Integer (number of points team gdi has)
nodpo As Intger (number of points team nod has)
runs As String (how long its been running as in 1w 1d 2h etc can be found out from the line [02:07:47] GameSpy mode active since 4/11/2004 - 14:45:51 PM )
End Type

once again this comes out this comes in different strings with the For next loop

and one final thing i need it to ignore blank lines and if something comes up that does not go with any of the above i need it to be put into the following

time
text

Thanks advanced - Nightma12
ASKER CERTIFIED SOLUTION
Avatar of Teycho
Teycho

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nightma12
Nightma12

ASKER

ok ive had ago at doing this function and i kinda messed up lol i sux

is there any chance of you being able to supply the code to use this function to produce what i am trying to do and detect which one it is etc

Thanks :)
This would be an example how to split the three chat modes:

Private Sub Command1_Click()
Dim myString As String, mySplit() As String, cTime As String, cNick As String
Dim cChatMode As String, cFristW As String, cSecondW As String, cThirdW As String, cFourthW As String
Dim cModerator As String, c As Integer

'myString = "[02:10:13] Host: DrkAgnt is a game moderator."
'myString = "[00:37:41] [Page] Host: DrkAgnt is a game moderator."
myString = "[00:37:41] [Team] ooops21: OK"

'detect chat mode
If InStr(1, myString, "Page") > 0 Then
        cChatMode = "Page"
        c = 1
    ElseIf InStr(1, myString, "Team") > 0 Then
        cChatMode = "Team"
        c = 1
    Else
        cChatMode = "All"
        c = 0
End If

mySplit = Split(myString, " ", -1)

On Error Resume Next         'we need it in case the line is shorter then the split ubound
cTime = Mid(mySplit(0), 2, 8)
cNick = mySplit(1 + c)
cFristW = mySplit(2 + c)
cSecondW = mySplit(3 + c)
cThirdW = mySplit(4 + c)
cFourthW = mySplit(5 + c)
cModerator = mySplit(6 + c)
'cChatMode - you already have it from above
End Sub

S
ok ty it works :)

there is just 2 problems

the first word does not get into the string

i also need it for everything after the 4th word


anybody know about the game_info & player_info bits?
ok i should be able to do player_info myself with the Split() function thxs! :)

just need game_info now :) (and a fixed v of Shaulis code lol)
Ok, i had a Loooooong look at the Split() function and finally fiqured it out!

Thanks Guys! :)