Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Regex, breaking apart a string.
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Martin




PostPosted: Thu Nov 25, 2004 5:23 pm   Post subject: Regex, breaking apart a string.

Suppose I had a string of characters and a dynamic array. Would there be any way, with regex, to break the string up into substrings seperated by specified characters?

I guess the best example of this would be breaking up a sentence into words.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Thu Nov 25, 2004 7:12 pm   Post subject: Re: Regex, breaking apart a string.

martin wrote:
Suppose I had a string of characters and a dynamic array. Would there be any way, with regex, to break the string up into substrings seperated by specified characters?

I guess the best example of this would be breaking up a sentence into words.


Well, basically, words are composed of letters, and possibly apostrophes. So we want to split on anything that isn't one of those characters.

For this, we can use a negative set.

code:
[^a-zA-Z']


Now, in Ruby, for instance:

code:
irb(main):004:0> "hello world".split /[^a-zA-Z']/i
=> ["hello", "world"]
irb(main):005:0>
rizzix




PostPosted: Thu Nov 25, 2004 9:18 pm   Post subject: Re: Regex, breaking apart a string.

martin wrote:
Suppose I had a string of characters and a dynamic array. Would there be any way, with regex, to break the string up into substrings seperated by specified characters?

I guess the best example of this would be breaking up a sentence into words.


yes u can and in java its a matter of
code:
String[] results = the_string.split("/");
where / is the separating delimiter.
Martin




PostPosted: Thu Nov 25, 2004 11:08 pm   Post subject: (No subject)

Oh, perfect. Is there a way to do it in C++ though?
wtd




PostPosted: Thu Nov 25, 2004 11:09 pm   Post subject: (No subject)

martin wrote:
Oh, perfect. Is there a way to do it in C++ though?


There is no standard regular expression library for C++. It is being included in the next C++ standard, from what I hear.
Martin




PostPosted: Thu Nov 25, 2004 11:43 pm   Post subject: (No subject)

Excellent.

I have been reading your tutorials, wtd, I just don't reply because I don't want to mess up the order :p
md




PostPosted: Thu Nov 25, 2004 11:58 pm   Post subject: (No subject)

if you need a good string class martin I've written one you can use. In fact if you ever looked at the project you would see it...

[edit] anyone else can get it from http://svn.nxor.org/ tis somewhere in hte BF-F project

[edit #2] tis in BF-f/src/cString there is a header file and a source file
wtd




PostPosted: Fri Nov 26, 2004 12:05 am   Post subject: (No subject)

Cornflake wrote:
if you need a good string class martin I've written one you can use. In fact if you ever looked at the project you would see it...


I don't see how this is better than std::string.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: