String Manipulation
Moderators: chulett, rschirm, roy
String Manipulation
Hi,
Input Data
ABC_xxx
ABC1_xxx
ABC2_xxx
yyy_ABC3_xxxx
I need to strip out all those characters to the left of _ that were before xxxx.
xxxx is just representation of string. So I need to strip out any char '...ABCn_'
n may or may not presetn. Some characters before ABC may or may not present.
An pointers?
Input Data
ABC_xxx
ABC1_xxx
ABC2_xxx
yyy_ABC3_xxxx
I need to strip out all those characters to the left of _ that were before xxxx.
xxxx is just representation of string. So I need to strip out any char '...ABCn_'
n may or may not presetn. Some characters before ABC may or may not present.
An pointers?
Re: String Manipulation
So you are only requiring the last bit of the field past the _? Ie the _xxxx will always be at the end? If so the easiest way would be to treat the underscore as a delimiter.
Perform a count of how many underscores there are in the field then use that number in the Field function to extract the last "column" as defined by your delimiter (which is '_'). You will probable need to add 1 to the number returned by the count. The syntax would be something like
Unfortunately I don't have access to a system at present, so I can't check the syntax, but it would be something like that.
Perform a count of how many underscores there are in the field then use that number in the Field function to extract the last "column" as defined by your delimiter (which is '_'). You will probable need to add 1 to the number returned by the count. The syntax would be something like
Code: Select all
InputField['_',Count(InputField,'_')+1,1]
dsdoubt wrote:Hi,
Input Data
ABC_xxx
ABC1_xxx
ABC2_xxx
yyy_ABC3_xxxx
I need to strip out all those characters to the left of _ that were before xxxx.
xxxx is just representation of string. So I need to strip out any char '...ABCn_'
n may or may not presetn. Some characters before ABC may or may not present.
An pointers?
-
- Premium Member
- Posts: 1255
- Joined: Wed Feb 02, 2005 11:54 am
- Location: United States of America
Re: String Manipulation
Yes. Shane's code will work. Here's the right syntax:ShaneMuir wrote:The syntax would be something like
InputField['_',Count(InputField,'_')+1,1]
Unfortunately I don't have access to a system at present, so I can't check the syntax, but it would be something like that.
Code: Select all
Field(InLink.Col,'_',Count(InLink.Col,'_')+1,1)
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Thanks for you inputs guys. I was extracting from Database, so manage to use database functions.
Code: Select all
SUBSTR(field, INSTR(field, '_',INSTR(article_id, 'ABC'))+1)
-
- Premium Member
- Posts: 1255
- Joined: Wed Feb 02, 2005 11:54 am
- Location: United States of America
Thanks, Ray. Didn't know about "delimited substring extraction".ray.wurlod wrote:Both syntaxes are correct (Shane's is called "delimited substring extraction") and will generate exactly the same object code.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
InputField[delimiter,start,count]
The delimiter asserts that you are dealing with a string (InputField) made up of zero or more substrings separated from each other by delimiter characters. For example "STRAWBERRY ICE CREAM" is a string containing 20 characters, or a string containing three words (substrings separated by " " characters), or a string containing four substrings delimited by "E", and so on.
When delimiter appears, the start and count integers refer not to individual characters but to delimited substrings. Thus, for example, if the variable Product contains "STRAWBERRY ICE CREAM" then the expression
Product["E",2,2] returns "RRY ICE CR" - as you can see, intervening delimiter characters are returned.
Finally, note that the third argument is a count of substrings to return, not the end position. In this respect your understanding was imprecise.
The delimiter asserts that you are dealing with a string (InputField) made up of zero or more substrings separated from each other by delimiter characters. For example "STRAWBERRY ICE CREAM" is a string containing 20 characters, or a string containing three words (substrings separated by " " characters), or a string containing four substrings delimited by "E", and so on.
When delimiter appears, the start and count integers refer not to individual characters but to delimited substrings. Thus, for example, if the variable Product contains "STRAWBERRY ICE CREAM" then the expression
Product["E",2,2] returns "RRY ICE CR" - as you can see, intervening delimiter characters are returned.
Finally, note that the third argument is a count of substrings to return, not the end position. In this respect your understanding was imprecise.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.