View previous topic :: View next topic
|
Author |
Message |
passion_sujesh
New User
Joined: 14 Mar 2008 Posts: 74 Location: India,Chennai
|
|
|
|
Hi,
Iam trying to selecta part of a string using SUBSTR function. This works fine if the string has no leding spaces. If the string has leading spaces, its not working as expected. Can any one help me in retaining the leading spaces while using substr.
My input (variable name - ws-xyz):
Code: |
"123456"
"234567"
" 4788" (two leading spaces)
"564786" |
ws-new-data = substr(ws-xyz,3,2)
My expected output:
Output i get:
The third record in the o/p is incorrect.
I think the leading space is removed before the substr, is there any way i can retain the leading space.
Thanks.
Code'd |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Could you post the trace output within code tags? |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
First of all, these:
ws-xyz
ws-new-data
are invalid variable names in REXX. Adjusting for that:
ws_new_data = Substr(ws_xyz,3,2)
Say "'"ws_new_data"'"
I get:
'34'
'45'
'47'
'47'
in my output. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
You have not shown how the values are assigned to the variable. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
even though the TS has not returned:
1. REXX is pretty tight. i have not found (in 20 years) any problem
other than my ability to understand the manual.
2. if you think something is not working 'as expected'.
do a little debugging.
use SAY LENGTH(variable)
use SAY variable
use TRACE. I find ?R to be most helpful. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Use:
the number of times I have found trailing blanks when there "weren't" any using this method! |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Nic's suggession of using > and < is valuable for COBOL displays also. Leading or trailing unprintable characters are spotted easily this way. |
|
Back to top |
|
|
|