Solved

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

Posted on 2004-04-21
6
187 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:Nightma12
  • 4
6 Comments
 

Accepted Solution

by:
Teycho earned 205 total points
ID: 10881361
The easiest way to do this is to use the Split() function.

It takes a string as an argument, and a delimiter on which to split, and returns an array of strings. In this case, you'd be using " " ( space ) as a delimiter.

str = "NOD Game Server Only"
arr = Split(str, " ")

Afterwards, arr =
arr(0) = "NOD"
arr(1) = "Game"
arr(2) = "Server"
arr(3) = "Only"

From there, it's easy to add th values into your UDT.  Of course, you'd need a slightly different routine for each different format in which the data comes back.

Brian
0
 
LVL 1

Author Comment

by:Nightma12
ID: 10881645
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 :)
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10881984
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:Nightma12
ID: 10891035
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?
0
 
LVL 1

Author Comment

by:Nightma12
ID: 10904586
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)
0
 
LVL 1

Author Comment

by:Nightma12
ID: 11017388
Ok, i had a Loooooong look at the Split() function and finally fiqured it out!

Thanks Guys! :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now