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
String Operation
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 29
- Joined: Mon Nov 20, 2006 7:17 am
- Location: Melbourne
String Operation
Saugat Dey
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Code: Select all
Str("|", InLink.Pos - 1) : "X" : Str("|", svMaxLen - InLink.Pos - 1)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 29
- Joined: Mon Nov 20, 2006 7:17 am
- Location: Melbourne
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.
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.
Saugat Dey
-
- Premium Member
- Posts: 1735
- Joined: Thu Mar 01, 2007 5:44 am
- Location: Troy, MI
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.
Priyadarshi Kunal
Genius may have its limitations, but stupidity is not thus handicapped.
Genius may have its limitations, but stupidity is not thus handicapped.
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
-
- Participant
- Posts: 29
- Joined: Mon Nov 20, 2006 7:17 am
- Location: Melbourne
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: