Page 1 of 1

String Operation

Posted: Fri May 08, 2009 1:39 am
by saugat_1982
Hi ,
I ve a input column which can give a integer value from 1 to 10 or NULL.
I am interested to create a string of char(20) where I will like to put a 'X' on position value provided by input col , and rest as empty space delimited by |.

For example , if input is 2
then output should look like '|X|||||||||'
if input is 5 then output should be '||||X||||||'

Please help , thanks in advance .

PS : For testing I am saying input will be 1 to 10 , but in real time it will be 1 to 500. So if I can successfully can do for 10 , my next step will be for 500.


Thanks Again

Posted: Fri May 08, 2009 2:38 am
by ray.wurlod

Code: Select all

Str("|", InLink.Pos - 1) : "X" : Str("|", svMaxLen - InLink.Pos - 1)
I've used svMaxLen as a stage variable rather than using 10 or 500 as a constant. Set its value in the initialization step and do not include a per-row derivation for it.

Posted: Fri May 08, 2009 3:31 am
by saugat_1982
Thanks Ray for the reply.
But I guess , it is not the requirement .

from input I will get a number (integer) .Lets say 'a'.
value of 'a' can be anything between 1 to 'n'(Max Value, in this case I m saying 10).

Now in output I want to generate a string (2n length).
Lets call the output string as 'outputstr'
And the shape of output will be like this

for i 1 to 2*n
if i%2 =0 then outputstr='|'
if i=2*a-1 then outputstr='X'
else output is NULL

Can you please suggest , Thanks Again.

Posted: Fri May 08, 2009 5:20 am
by priyadarshikunal
saugat_1982 wrote:Thanks Ray for the reply.
But I guess , it is not the requirement .

from input I will get a number (integer) .Lets say 'a'.
value of 'a' can be anything between 1 to 'n'(Max Value, in this case I m saying 10).

Now in output I want to generate a string (2n length).
Lets call the output string as 'outputstr'
And the shape of output will be like this

for i 1 to 2*n
if i%2 =0 then outputstr='|'
if i=2*a-1 then outputstr='X'
else output is NULL

Can you please suggest , Thanks Again.



Read carefully what Ray is suggesting. It will give you the desired result or may be you have to change it a bit to get the result you want.

If you want to generate the string of length 2n then you might have to pad a space between pipes. Str function will do that. Try it first.

Posted: Fri May 08, 2009 5:40 am
by Sainath.Srinivasan
Your requirement appears incomplete.

Who is be using your output? With so many pipes, the receiving party will have an heck of translation to do.

Posted: Fri May 08, 2009 5:43 am
by saugat_1982
why "the receiving party will have an heck of translation" ?
output is expected to 'n' numbers of characters/NULL separted by each pipe

Posted: Sun May 10, 2009 4:42 pm
by ray.wurlod
It is not possible to include NULL in a string. As soon as you use NULL as an operand, the result is necessarily NULL. What did you have in mind here?