View previous topic :: View next topic
|
Author |
Message |
renjithravi
New User
Joined: 28 Jul 2008 Posts: 14 Location: Chennai
|
|
|
|
HI,
I have a variable declared in PLI as char..this variable contains about 10,000 length of data. The data has special characters, numbers and alphabets. I want to search the occurance of 6 consecutive numbers in this set of 10000 characters. Which function in PLI i can use it and how to use it. Please help me in this.
Thanks and regards
Renjith |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
try INDEX |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
RESULT = INDEX('SHARP FORTUNE','R');
this will give you value 4 ...INDEX function always looks for the left most occurence of the string mentioned ...now if you want to search for the 2nd occurence of R give
RESULT = INDEX('SHARP FORTUNE','R',5); ... or
RESULT = INDEX('SHARP FORTUNE','R',INDEX('SHARP FORTUNE','R')+1); |
|
Back to top |
|
|
renjithravi
New User
Joined: 28 Jul 2008 Posts: 14 Location: Chennai
|
|
|
|
Hope you have misunderstood my scenario...
i have a variable declared like this
DCL A CHAR(1000) INIT 'FJDJOOIIPIPI1256978KFDFKDK.....'
i want to search the occurance of six consecutive numbers from the variable A i.e. 125697.... |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
RESULT = INDEX(A,'1256978'); this will give value of result as 13 ... try it out ... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Hope you have misunderstood my scenario... |
Possibly because you have not provided a clear definition. . .
Do you want the location of the first occurence any 6 digits or do you want the location of the first occurence of "125697"?
What about multiple occurences of 6 digits in the string?
You need to post multiple sample "input" strings and what you want as "output" for each input string from the new process. |
|
Back to top |
|
|
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
You have to write your own logic using SEARCH and SUBSTR builtin functions. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
You have to write your own logic using SEARCH and SUBSTR builtin functions. |
How will SEARCH and SUBSTR identify the position of 6 consecutive numbers?
It may not matter as Renjith has neither provided the requested info nor even replied in over a month. . . |
|
Back to top |
|
|
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
using SEARCH find out the position of first occurence of number.
Again SEARCH for next occurence of number(strating from previous position) , and subtract with previous position(see whether it is zero or not)..
Finally use SUBSTR to extract the string.
But here we have take care that we need 6 consecutive numbers |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
the quick and dirty way is to go for a two stage approach
Code: |
work_string=translate(orig_string,'$$$$$$$$$$','0123456789')
ofst = index(work_string,'$$$$$$')
|
the $ is a place holder, use a character that will not be in Your string |
|
Back to top |
|
|
|