Can someone help me out. I want to split a string at a 'number' position and then move all the splited parts into holder. LIke this
1 this is 2 an example 3 string field
I want to split at 2 and 3 and remove any space in the strings. The result will be like this:
1 thisis
2 anexample
3 stringfield
Can someone help me, please.
Split a string at a number
Moderators: Snowy, thx4allthefish, YuriT, Gothmog
-
- Posts: 297
- Joined: Tue Mar 01, 2005 12:57 pm
Re: Split a string at a number
This sounds like a wonderful "Programming 101" exercise - it also sounds like something you should do for yourself and at least post YOUR efforts to solve it, before you ask US to spoon-feed you.
You are aware of the SPLIT command? And of the various string comparison operators and other string commands? There are probably a zillion ways to do this. You should come up with something on your own first. I would be ashamed to ask someone else to give me the answer to this before I tried on my own, even (or especially) many years ago when first I started to program.
You are aware of the SPLIT command? And of the various string comparison operators and other string commands? There are probably a zillion ways to do this. You should come up with something on your own first. I would be ashamed to ask someone else to give me the answer to this before I tried on my own, even (or especially) many years ago when first I started to program.
Re: Split a string at a number
SPLIT is not of real use to you here because you need to split at any number. Try FIND + MATCH OFFSET and then string(offset).
And yes, ese_pinche_ABAP is right. This is a simple task that you can do in hundreds of ways, you just have to try.
And yes, ese_pinche_ABAP is right. This is a simple task that you can do in hundreds of ways, you just have to try.
-
- Posts: 297
- Joined: Tue Mar 01, 2005 12:57 pm
Re: Split a string at a number
Actually I could do it using SPLIT, even recursively, but your suggestion Yuri is probably better...
Something along the lines of:
if the string contains any of <numbers 0-9>
assign that number to var1
SPLIT at var1
..and I'll leave the rest as an exercise to the reader, as the textbooks say!

Something along the lines of:
if the string contains any of <numbers 0-9>
assign that number to var1
SPLIT at var1
..and I'll leave the rest as an exercise to the reader, as the textbooks say!

-
- Posts: 2
- Joined: Tue Jun 07, 2011 2:34 am
Re: Split a string at a number
Thank for all the help. I've done it.
I used string offset and loop to do it. It even worked too great to make me wonder why the hell couldn't i come up with it earlier.
I used string offset and loop to do it. It even worked too great to make me wonder why the hell couldn't i come up with it earlier.