Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to search a string in PL/I?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
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    Post subject: How to search a string in PL/I?
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue Jul 29, 2008 9:37 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue Sep 09, 2008 7:13 pm    Post subject:
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Wed Sep 10, 2008 7:29 pm    Post subject: Reply to: How to search a string in PL/I?
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    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm
No new posts Need a help how to replace a string i... gurunath82 CLIST & REXX 12 Tue Jul 26, 2016 11:43 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us