how can i create my custom string edition

how can i create my custom string edition

  
Hi everyone,
I have a little problem and i need some help asap if possible:
I want to create a sub-string in a local variable:
Substr(GTIN , differentFromZeroIndex(GTIN) , Length(GTIN))

so i need to do something like this pseudo-code:

int differentFromZeroIndex(string str){
for (i=0; i< str.lenght; i++)
                if (str[i] != '0')
                               return i;
return -1; 


examples:
diffrenteFromZeroIndex("0000123045") returns 4
Substr returns "123045"
diffrenteFromZeroIndex("00123045") returns 2
Substr returns "123045"
diffrenteFromZeroIndex("0123045") returns 1
Substr returns "123045"
diffrenteFromZeroIndex("123045") returns 0
Substr returns "123045"


My main question is: how can i create my custom code?

Many thanks in advance

TextToInteger() ?

If it is not numeric (or a number bigger than Integer) I had to do it once in XSLT and the best way was like this:

Find first non-0
substr(replace(Str,0,""),0,1)

Find its position
index(Str,FillWithFirstNon0)

Ignore everything before that position
substr(Str,FoundPosition,length(Str))

Makes any sense?

Now together
substr(Str, index(Str,substr(replace(Str,0,""),0,1)),length(Str))

Nuno Reis wrote:
TextToInteger() ?

If it is not numeric (or a number bigger than Integer) I had to do it once in XSLT and the best way was like this:

Find first non-0
substr(replace(Str,0,""),0,1)

Find its position
index(Str,FillWithFirstNon0)

Ignore everything before that position
substr(Str,FoundPosition,length(Str))

Makes any sense?

Now together
substr(Str, index(Str,substr(replace(Str,0,""),0,1)),length(Str))
 
 Thanks!!! And sorry for my mistakes in the examples, i already fixed it ;)
 
Oh, even easier.

For that you just need the
substr(replace(Str,0,""),0,1)
I was wondering, in this solution:
substr(replace(Str,0,""),0,1)

if str = "000123045"
replace(Str,0,"") will be "12345"
and finnally the substr(replace(Str,0,""),0,1) will be "1"
and my idea is to return "123045"
or i'm missing something?

Thanks
I misread the correction. My second post is "first non-0 digit". Not what you wanted.

substr(replace(Str,0,""),0,1)
returns first non-0


index(Str, substr(replace(Str,0,""),0,1))
returns index of the first non-0, a.k.a., number of zeros
, a.k.a., your diffrenteFromZeroIndex function

substr(Str, index(Str,substr(replace(Str,0,""),0,1)),length(Str)) is the look of your final SubStr.