Page 1 of 1

Reading filenames up to certain position.

Posted: 21 Apr 2011 21:03
by tiago
How to read each filename up to letter in position X from left to right, right to left...? Is there a command I am missing? substr() gives me a specific string but not whole sections. strpos() and strlen() are close but amiss either.

Re: Reading filenames up to certain position.

Posted: 21 Apr 2011 21:47
by Stefan
tiago wrote:How to read each filename up to letter in position X from left to right, right to left...? Is there a command I am missing?
substr() gives me a specific string but not whole sections.
strpos() and strlen() are close but amiss either.
What do you mean by "whole sections" ?
Examples please.

substr(string, [start], [length])

Give me first three signs of string "string":
msg substr( "string" , , 3 ); // 'str'

Give me last three signs of string "string":
::msg substr( "string" , strlen( "string" ) -3 , ); // 'ing'

Give me three signs starting at sign 2 of string "string":
::msg substr("string", 1, 3); // 'tri'

Note:
Calculation starts from '0': first sign/char is at pos '0'
Start point '0' and end point 'last sign of string' are implicit and must not be entered into the command.

Re: Reading filenames up to certain position.

Posted: 21 Apr 2011 23:56
by tiago
substr(string, [start], [length]) is what I need, and I probably overlooked it on help and misunderstood the meaning of "lenght". Thank you Stefan.