Difference between revisions of "Substr"

From SDU
Jump to: navigation, search
m
(fix missleading argument length.)
Line 9: Line 9:
 
Overloaded method to return a string within a string
 
Overloaded method to return a string within a string
  
string substr(string str, int start, int finish)  
+
string substr(string str, int start, int length)  
  
 
string substr(string str, int start) // reads to the end of the string for finish  
 
string substr(string str, int start) // reads to the end of the string for finish  
Line 26: Line 26:
 
myString = substr(otherString,sindex(otherString,"a"));
 
myString = substr(otherString,sindex(otherString,"a"));
  
// myString = "a string"
+
// myString == "a string"
 +
 
 +
myString = substr(otherString,sindex(otherString,"is",4));
 +
 
 +
// myString == "is a"

Revision as of 12:25, 2 October 2008

To make corrections or additions to this article, select the edit tab above.
To discuss or ask questions about this article, select the discussion tab above.

Overloaded method to return a string within a string

string substr(string str, int start, int length)

string substr(string str, int start) // reads to the end of the string for finish


Can be used in conjuction with sindex to retrieve start index.

eg.

string myString;

string otherString;

otherString = "this is a string";

myString = substr(otherString,sindex(otherString,"a"));

// myString == "a string"

myString = substr(otherString,sindex(otherString,"is",4));

// myString == "is a"