Removing a character from the string
Can you provide a code for a program that searches an alphanumeric field for a character and then deletes that character?
When you say, delete the character, I hope you mean remove it from the string. I will show you a way to do that along with a way to replace that character in the string.
Here is how I would write the code to replace the character with a space.
XX = the character that you are looking to replace
N= the position the character is found in.
*IN88 will be turned on if the SCAN is successful.
C 'XX' SCAN CHARFIELD N 88 C IF *IN88 = *ON C EVAL %SUBST(CHARFIELD:N:1) = ' ' C ENDIF Here is how I would write the code to delete the character. This is written on the assumption of a 10 character length field. If your field is a different length, then replace the 10 with the length of your field. XX = the character that you are looking to replace N= the position the character is found in. C 'XX' SCAN CHARFIELD N 88 C IF *IN88 = *ON C EVAL WORKFIELD1 =%SUBST(CHARFIELD:1:N-1) C EVAL WORKFIELD2 =%SUBST(CHARFIELD:N+1:10-N) C EVAL WORK =%TRIM(WORKFIELD1) + %TRIM(WORKFIELD C ENDIF
==================================
MORE INFORMATION ON THIS TOPIC
==================================
The Best Web Links: Tips, tutorials and more.
Ask your systems management questions--or help out your peers by answering them--in our live discussion forums.
Read this Search400.com Featured Topic: Managing your iSeries.
Ask the Experts yourself: Our systems management gurus are waiting to answer your technical questions.
Dig Deeper on Performance
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.
Meet all of our AS/400 experts
View all AS/400 questions and answers
Start the conversation
0 comments