HyPhy message board
http://www.hyphy.org/cgi-bin/hyphy_forums/YaBB.pl
Methodology Questions >> How to >> split a string
http://www.hyphy.org/cgi-bin/hyphy_forums/YaBB.pl?num=1400503453

Message started by Miguel on May 19th, 2014 at 5:44am

Title: split a string
Post by Miguel on May 19th, 2014 at 5:44am
Hi,

Just a very simple question. How can we split a string according to a given pattern?
For example,

Code (]
MyInString = "0-199"
[/code):

And then extract the information of the numbers in two new variables like:
[code]
number1 = 0
number2 = 199

So just split the string in two numbers at the "-"..

I've been trying to do it with "GetString" and "Rows" but I coud not find the way  :-[
Ideas?. Many thanks!!  :D

Best,
Miguel

Title: Re: split a string
Post by Sergei on May 19th, 2014 at 11:29am
Hi Miguel,

Use this:

[code]
LoadFunctionLibrary ("ReadDelimitedFiles");

str = "0-199";
split_string = splitOnRegExp (str, "-");

fprintf (stdout, split_string, "\n");
[/code]

There are other utility function in ReadDelimitedFiles (look at the source: TemplateBatchFiles/Utility/ReadDelimitedFiles.bf)

Sergei

Title: Re: split a string
Post by Miguel on May 19th, 2014 at 12:44pm
Great!  :D
Many thanks sergei!   :)

Best,
Miguel

HyPhy message board » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2024. All Rights Reserved.