Operating with substrings in strings

Kirk McDonald kirklin.mcdonald at gmail.com
Fri Aug 18 11:56:21 PDT 2006


Heinz wrote:
> Hi, i haven't found a function in the phobos lib to read a block of chars of a
> given length from a string taking the start index as a parameter, for example:
> we have the word "hello", i want to read starting from index 1 and i want this
> substring to have a length of 2, so the result should be "el", i've seen this
> in other languages, the function looks like: GetSubString(string mystring, int
> startindex, int length).
> 
> Is there a way to acomplish this?
> 
> Thx

Slicing:

char[] h = "hello";
char[] sub = h[1..3] // Slice the string "hello"
writefln(sub); // Prints "el"

http://digitalmars.com/d/arrays.html#slicing

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org



More information about the Digitalmars-d-learn mailing list