Welcome, Guest. Please Login
YaBB - Yet another Bulletin Board
 
  HomeHelpSearchLogin  
 
String manipulation - removing/truncating/ strings (Read 2113 times)
Aidan Budd
YaBB Newbies
*
Offline


Monkey fed...

Posts: 29
Heidelberg, Germany
Gender: male
String manipulation - removing/truncating/ strings
Aug 13th, 2008 at 8:49am
 
Hi Sergei

Very quick question - as I'm estimating parameters over a large-ish number of trees (200 or so) I build a long string to specifcy my likelihood function, and use "ExecuteCommands" to create the function.

The way I'm building this string, I'm sticking a comma after every element that gets passed as an argument, so I end up with a string that looks like this

LikelihoodFunction lf = (f1,t1,f2,t2.....f200,t200,    
[which I then would add an ");" to the end of before executing]

My question - is there a simple way to remove the terminal comma on this string, or do I need to be more careful about building the string to catch the case when I last go through the loop (and then, in that case, not add the comma)

Thanks

Aidan
Back to top
 

Aidan Budd&&Computational Biologist&&EMBL Heideberg, Germany
 
IP Logged
 
Sergei
YaBB Administrator
*****
Offline


Datamonkeys are forever...

Posts: 1658
UCSD
Gender: male
Re: String manipulation - removing/truncating/ strings
Reply #1 - Aug 13th, 2008 at 10:04am
 
Dear Aidan,

If you have a string variable (say myString), here's the code to remove the last k characters:

Code:
myStringMinusLastKChars = myString[0][Abs(myString)-k-1];
 



The string[from][to] operation retrieves a substring from index 'from' to index 'to' (both 0-based and inclusive).

HTH,
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
 
Aidan Budd
YaBB Newbies
*
Offline


Monkey fed...

Posts: 29
Heidelberg, Germany
Gender: male
Re: String manipulation - removing/truncating/ strings
Reply #2 - Aug 13th, 2008 at 10:09am
 
thanks a lot for getting back to me on this so quickly, Sergei - that was exactly what I was looking for.

Aidan
Back to top
 

Aidan Budd&&Computational Biologist&&EMBL Heideberg, Germany
 
IP Logged