IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to search a string in PL/I?


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
renjithravi

New User


Joined: 28 Jul 2008
Posts: 14
Location: Chennai

PostPosted: Tue Jul 29, 2008 10:31 am
Reply with quote

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
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Tue Jul 29, 2008 12:53 pm
Reply with quote

try INDEX
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Jul 29, 2008 2:17 pm
Reply with quote

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
View user's profile Send private message
renjithravi

New User


Joined: 28 Jul 2008
Posts: 14
Location: Chennai

PostPosted: Tue Jul 29, 2008 5:10 pm
Reply with quote

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
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Jul 29, 2008 5:15 pm
Reply with quote

RESULT = INDEX(A,'1256978'); this will give value of result as 13 ... try it out ...
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jul 29, 2008 9:37 pm
Reply with quote

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
View user's profile Send private message
murugan_mf

Active User


Joined: 31 Jan 2008
Posts: 148
Location: Chennai, India

PostPosted: Tue Sep 09, 2008 4:32 pm
Reply with quote

You have to write your own logic using SEARCH and SUBSTR builtin functions.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Sep 09, 2008 7:13 pm
Reply with quote

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
View user's profile Send private message
murugan_mf

Active User


Joined: 31 Jan 2008
Posts: 148
Location: Chennai, India

PostPosted: Wed Sep 10, 2008 7:19 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Sep 10, 2008 7:29 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts file manager is doing string conversion IBM Tools 3
Search our Forums:

Back to Top