Welcome, Guest. Please Login
YaBB - Yet another Bulletin Board
 
  HomeHelpSearchLogin  
 
split a string (Read 1071 times)
Miguel
Junior Member
**
Offline


Hi Hyphy!

Posts: 53
CBMSO, CSIC (Spain)
Gender: male
split a string
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"
 


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  Embarrassed
Ideas?. Many thanks!!  Cheesy

Best,
Miguel
Back to top
 
WWW WWW  
IP Logged
 
Sergei
YaBB Administrator
*****
Offline


Datamonkeys are forever...

Posts: 1658
UCSD
Gender: male
Re: split a string
Reply #1 - 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");
 



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

Sergei
Back to top
 

Associate Professor
Division of Infectious Diseases
Division of Biomedical Informatics
School of Medicine
University of California San Diego
WWW WWW  
IP Logged
 
Miguel
Junior Member
**
Offline


Hi Hyphy!

Posts: 53
CBMSO, CSIC (Spain)
Gender: male
Re: split a string
Reply #2 - May 19th, 2014 at 12:44pm
 
Great!  Cheesy
Many thanks sergei!   Smiley

Best,
Miguel
Back to top
 
WWW WWW  
IP Logged