Skip to Content (Press Enter)
OutSystems.com
Personal Edition
Community
Support
Training
Training
Online Training
Developer Schools
Boot Camps
Certifications
Tech Talks
Documentation
Documentation
Overview
ODC
O11
Forums
Forge
Get Involved
Get Involved
Jobs
Ideas
Members
Mentorship
User Groups
Platform
Platform
ODC
O11
Search in OutSystems
Log in
Get Started
Back to Forums
Rui Maciel
2
Views
5
Comments
how can i create my custom string edition
Question
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
Nuno Reis
MVP
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
))
1 reply
07 Jan 2014
Show thread
Hide thread
Rui Maciel
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 ;)
Nuno Reis
MVP
Oh, even easier.
For that you just need the
substr(replace(
Str
,
0
,""),0,1)
Rui Maciel
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
Nuno Reis
MVP
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.
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
See the full guidelines
Loading...