Go Back   RunUO - Ultima Online Emulation > RunUO > RunUO Post Archive

RunUO Post Archive The Archvie

Reply
 
Thread Tools Display Modes
Old 01-12-2005, 08:43 AM   #1 (permalink)
Forum Expert
 
Join Date: Oct 2002
Location: Germany (american though)
Age: 32
Posts: 957
Thumbs up How to parse strings

took me a while to figure this out. Someone out there might be looking for a contribution like this.

lets use the text "parsing a string" for this example.

Code:
// set up the temporary string
string tempstring = "parsing a string";
// set up your split delimiter
string[] split = tempname.Split( ' ' ); // in this case, a blank space
from.SendMessage(split[0]); // sends "parsing"
from.SendMessage(split[1]); // sends "a"
from.SendMessage(split[2]); // sends "string"
of course if the delimiter is different, you can parse it differently:

Code:
// set up the temporary string
string tempstring = "just another ~ example";
// set up your split delimiter
string[] split = tempname.Split( '~' ); // in this case, ~
string firsthalf = split[0]; 
firsthalf = firsthalf.Trim();// you want to trim the blank space off the end
string secondhalf = split[1]; 
secondhalf = secondhalf.Trim();// you want to trim the blank space off the beginning
from.SendMessage(firsthalf); // sends "just another"
from.SendMessage(secondhalf); // sends "example"
Have fun

**edit** trimmed the wrong way
Jarrod is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5