Function for extracting delimited substrings in a string

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
psluser
Premium Member
Premium Member
Posts: 39
Joined: Tue Apr 22, 2008 7:00 am
Location: Pune, India

Function for extracting delimited substrings in a string

Post by psluser »

Hi,

We have a requirement wherein we need to extract substrings from a string where the delimiter is "^~"(basically delimiter is more than 1 character.)

Field function supports delimiter with a single character.

For example :-
input_string = A:B^~C:D^~E:F
We want to get individual strings A:B, C:D, E:F
Delimiter is "^~".

If anyone is aware of any such function that can be used to get delimited substrings where delimiter is more than a character, please let us know.
Thanks in advance.
hamzaqk
Participant
Posts: 249
Joined: Tue Apr 17, 2007 5:50 am
Location: islamabad

Post by hamzaqk »

are the smiles coming through in your data too ? :lol:
Last edited by hamzaqk on Thu Oct 23, 2008 5:17 am, edited 1 time in total.
Teradata Certified Master V2R5
psluser
Premium Member
Premium Member
Posts: 39
Joined: Tue Apr 22, 2008 7:00 am
Location: Pune, India

Post by psluser »

hamzaqk wrote:are the smile coming through in your data too ? :lol:
Hi,

Please consider the example as below for clarification:-
input_string = A:B^~C:M^~E:F
We want to get individual strings A:B, C:M, E:F
Delimiter is "^~".

Thanks,
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:idea: A couple of tips...

Always 'Preview' your posts so you know what they will look like.

Next time you have this problem, enable the 'Disable Smilies in this post' option.
-craig

"You can never have too many knives" -- Logan Nine Fingers
hamzaqk
Participant
Posts: 249
Joined: Tue Apr 17, 2007 5:50 am
Location: islamabad

Post by hamzaqk »

How many columns? how many records ?

is the data format fixed and always like A:B^~C:M^~E:F ?? that is two charcter_1:character_2^~charcter_3:character_4. If you have fixed columns you can use the substring to extarct the data and concatenate them at the end. if the data is hefty why not write a routine/function do it?
Teradata Certified Master V2R5
DS_SUPPORT
Premium Member
Premium Member
Posts: 232
Joined: Fri Aug 04, 2006 1:20 am
Location: Bangalore

Post by DS_SUPPORT »

Convert the ^~ to a single delimeter by using CONVERT and use the field function

Code: Select all

Convert("^~","|",InputLink.Col)
psluser
Premium Member
Premium Member
Posts: 39
Joined: Tue Apr 22, 2008 7:00 am
Location: Pune, India

Post by psluser »

DS_SUPPORT wrote:Convert the ^~ to a single delimeter by using CONVERT and use the field function

Code: Select all

Convert("^~","|",InputLink.Col)

Thanks for the reply, but the reason for using multiple char as delimiter is that such type of combination of char (not exactly what is given in the example )may not be present in the production data.

In case of single char it will fail for the following example:-
input string :- A:B^C:^D^E:F
expected substrings :- A:B, C:^D, E:F
Delimiter :- ^

In the above example it will fail because sub strings returned would be :- A:B, C:, D, E:F

Apart from using multiple char as delimiter, instead we can use a character thats not present on the keyboard. Can this be achieved in DataStage?

Any pointers in this regard would be very helpful.

Thanks
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

You can convert to the system variable @FM as your single character delimiter. It's not on your keyboard.

Mike
cedua
Participant
Posts: 22
Joined: Mon Nov 10, 2008 1:21 pm

Post by cedua »

psluser wrote:
hamzaqk wrote:are the smile coming through in your data too ? :lol:
Hi,

Please consider the example as below for clarification:-
input_string = A:B^~C:M^~E:F
We want to get individual strings A:B, C:M, E:F
Delimiter is "^~".

Thanks,
You can use the Field() function....

Something like Field(input_string,"^~",2)

hope it helps...
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Nope, 'fraid not. Field() only supports a single character delimiter, hence all of the other shenanigans people are discussing.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kandyshandy
Participant
Posts: 597
Joined: Fri Apr 29, 2005 6:19 am
Location: Singapore

Post by kandyshandy »

Hello, Do you know how many delimiters will be there in a string? Is it fixed or variable?
Kandy
_________________
Try and Try again…You will succeed atlast!!
cedua
Participant
Posts: 22
Joined: Mon Nov 10, 2008 1:21 pm

Post by cedua »

JUST AN IDEA

It could be with "doble pass" field function..... (based on the example)
Post Reply