Split String

I have a strings that includes mail address with ';'
separetor so I need to split this string into substrings or
into an array like in
C#
Type string[];
Type = str.Split(';');
How can i do this in powerbuilder? Is there a function like
that or i need to write it myself?
0
Kemal
4/14/2008 4:37:51 PM
sybase.powerscript 7704 articles. 0 followers. Follow

2 Replies
1911 Views

Similar Articles

[PageSpeed] 14

Here is some code I found a long time ago.


global function integer gf_parse_plus (string as_string, ref string 
as_array[], ref integer ai_count, string as_delimiter);// Function  Takes a 
string and separates elements into an array

// Returns  0 = success
//     1 = error
//
// as_string  Source string containing values delimited by as_delimiter
// as_array[]  Destination array, passed by value
// ai_count   Returns count of items in array
// as_delimiter delimiter value

int   li_pos   // position of commas
int   li_len   // string parsing
int   li_start   // string parsing
string  ls_item   // single item parsed from string

if Len ( as_string ) < 1 then
 ai_count = 0
 return 1
end if

// parse out items and insert into array

li_pos  = 1
li_start = 1
ai_count = 0

DO WHILE li_pos > 0

 li_pos = Pos ( as_string, as_delimiter, li_start )

 if li_pos = 0 then
  ls_item = Mid ( as_string, li_start )
 else
  ls_item = Mid ( as_string, li_start, li_pos - li_start )
 end if


 ls_item = Trim ( ls_item )

 if Len ( ls_item ) > 0 then
  ai_count++
  as_array[ai_count] = ls_item
 end if

 li_start = li_pos + 1

LOOP

return 0
-- 
Terry Dykstra (TeamSybase)
http://powerbuilder.codeXchange.sybase.com/
http://casexpress.sybase.com/cx/cx.stm
product enhancement requests:
http://my.isug.com/cgi-bin/1/c/submit_enhancement

<Kemal> wrote in message news:4803885f.6449.1681692777@sybase.com...
>I have a strings that includes mail address with ';'
> separetor so I need to split this string into substrings or
> into an array like in
> C#
> Type string[];
> Type = str.Split(';');
> How can i do this in powerbuilder? Is there a function like
> that or i need to write it myself? 


0
Terry
4/14/2008 6:08:19 PM
Kemal wrote:
> I have a strings that includes mail address with ';'
> separetor so I need to split this string into substrings or
> into an array like in
> C#
> Type string[];
> Type = str.Split(';');
> How can i do this in powerbuilder? Is there a function like
> that or i need to write it myself?

I find most of the time you don't really need an array since you intend 
to process the data from start to finish anyway. I often found myself 
writing code like the following to parse strings;

do while str<>''
   value=left(str,pos(str+';',';')-1)
   str=mid(str,pos(str+';',';')+1)

   // process value....

loop

So at some point I generalised that coding pattern and wrote a helper 
function;

global function boolean f_token (ref string as_source, string as_delim, 
ref string as_value);
boolean lb_ret
long ll_pos

lb_ret=as_source<>''
ll_pos=Pos (as_source + as_delim, as_delim)
as_value = trim (Left (as_source, ll_pos - 1))
as_source = trim (Mid (as_source, ll_pos + Len (as_delim)))
return lb_ret
end function

Then I overloaded it with different data types to convert the value 
automatically;

global function boolean f_token (ref string as_source, string as_delim, 
ref decimal adc_value)
global function boolean f_token (ref string as_source, string as_delim, 
ref datetime adtm_value)
global function boolean f_token (ref string as_source, string as_delim, 
ref boolean ab_value)
....

(conversion and error handling left as an exercise for the reader)


So now I end up with code that looks like this;

ls_file = filereadex( ....

do while f_token(ls_file, '~r~n', ls_line)

   f_token(ls_line, ',', ldc_key)
   f_token(ls_line, ',', ls_name)

   ...

   insert ...
   values (:ldc_key, :ls_name, ...
loop
0
Jeremy
4/16/2008 1:17:57 PM
Reply:

Similar Artilces:

Why String.Split(char[]) is possible but String.Split(string[]) is Not!
Hi everyone, i have a string for e:g String st= "Delete a record****** *************************************************** Delete Manually PatID=123456 PatName=navdeep *****Delete a record****** *************************************************** Delete Manually *****************PatID=123 PatName=navdeep6666" I need to Split this String by "Delete a record" string. Now, str[] will contain the array elements. str = st.Split("Delete a record"); Please Help Regards Navdeep check below link or try code  http://www.codeproject.co...

split string by string
Hi All I am trying to split a string with other string. Does any one help me how to do this.I have "237943--;--dgsa78a--;--dasd732" I want to split with --;-- And ideas please thanks,Aruna.G     string contents = "237943--;--dgsa78a--;--dasd732"; you can do contents.split(';')which would split it on ; Thanks,Karan~ Remember To Mark The Post(s) That Helped You As The ANSWER ~ You can use String.Split(String[], StringSplitOptions)   string source = "237943--;--dgsa78a--;--dasd732"; string[] ...

how to split a string by a string not a char?
I've used the split('?') function on strings to good effect to delimit them up based on a single char but I'm looking through the overloads and can't see one for how to split a string by a string pattern. My source string is called Session["basket"] and is in the format A/B and I want to change it also include C, however A/B/C and split by '/' won't be 100% reliable because C is actually gotten from user input so they could input forwardslashes and thus mess things up, so a possible solution may be to do something like A#@#B#@#C and then do a Session...

Splitting string using split()
Gurus: I have a string like this: $s = 'jablow@xxx.com, "Blow, Joe" <jablow@xxx.com>,Joe Blow <jablow@xxx.com>' And I want to be able to split it up. Using split, like this: my @addresses = split(/, ?/, $s); But obviously this causes a problem because of the comma inside the quotes. I want three parts, and it splits it into four. Is there some module or nice way to have the commas inside quotes ignored? Reply to perlbeginner@mikemiller.net if possible as I'm only getting the daily digest of this list. Thanks, -Mike This seems ...

Splitting a String into Usable strings
How do I split up a string that has data that is separated by a comma?  I used the SPLIT method, but the method put the data into an array.  The array will not allow me to send the data into a string to be used.    What can I do??? What do you want to achieve by splitting the string? An array will let you access each segment individually. string numbers = "1,2,3,4"; string[] s = numbers.Split(",".ToCharArray()); string firstNumber = s[0]; In case you want to bring the splitted string back to a flat string you should take a look at the String.J...

String.Split a StreamReader.ReadLine() string
Hello one and all, I'm developing a system to take a CSV file uploaded via the web, parse it, and insert the values into an SQL database. My sticking point comes when I try to split() the string returned by readline() on the file. The following code snippet works for me: tokens = "one,two,three,four".Split(",") for each token in tokens response.write("<td>"+token+"</td>") next However, if I take the next line in the CSV, read using StreamReader.ReadLine on the PostedFile.InputStream, I receive "Object refer...

splitting a string of alphanumeric into two string
Hi, Just a question on what the easiest way is to split a string that starts w/ alphabetical characters and ends w/ numeric numbers into two.  i.e. String: JonPT233 Split the above into two string:  1st string:  JonPT 2nd string:  233 I was looking at the Split() function but it doesn't have a direct way of splitting aphanumeric characters into what I want...so is going through character one by one and creating two separate arrays checking if it's alphabetical or numeric the only way or is there an easier, more direct way of doing this?  thanks. The ...

splitting the string without using split function
...\M3\1_Requirements\Ashish_M3_Functional_Requirements_Document.doc splittiing the string in such a way that  i wil get the last part of the stringstarted with \ (splitting the string without using split function) so output will be  Ashish_M3_Functional_Requirements_Document.doc The System.IO.Path class provides a safe way for extracting all the different parts of a file name/path, so in this case I would be tempted to use that.RegardsDave...

splitting a string of characters and numbers into separate strings
Hi,  I was looking at the Split() function in vb.net but don't know if there's an easier way to do this.  I have a string that is alphanumeric.  It starts with alphabetical characters and ends with integers.  The length varies from one record to another.  I had to concatenate the two to have them appear together in a dropdown list.  However, when a user selects it, I need to split it in two different strings, one that holds just the alphabetical characters and one that has just the integer values.  Is there an easier way than just going through the...

splitting strings
Hello, Given the string 'abcdefghijklmnopq', I wish to add a line break every 5 characters: abcde fghij klmno pq Method 1 below works, but my split() in method 2 captures 'something unexpected' at each match. Could someone please tell me what is split capturing that I am not seeing? Thanks in advance for your answers, -Hien My script: ========== #!/usr/bin/perl -w use strict; my $foo = 'abcdefghijklmnopq'; # Method 1 print( "\nMethod 1\n" ); my $foo_length = length( $foo ); for( my $i = 0; $i < $foo_length; $i +...

splitting the string.
Hello Perl Experts, I want to split the string $a ="abcdef"; as @asplit = ("a","b","c","d","e","f"). Is this possible. Kindly provide your valuable inputs. Thank you very much. Regards, Rajagopal __________________________________________________ Do You Yahoo!? Yahoo! Movies - coverage of the 74th Academy Awards� http://movies.yahoo.com/ $a =3D'abcdef'; @arr =3D split(//,$a); print "@arr"; > ---------- > From: Raja Gopal[SMTP:rajaghv@yahoo.com] > Sent: Thurs...

splitting string
------_=_NextPart_001_01C23FA5.9CD6ED00 Content-Type: text/plain; charset="iso-8859-1" hi All, I have string as given below: M:\sun1\train\test\Soarian_Context_Sensitive_Coordination_File From this string i need to split indivually and get Soarian_Context_Sensitive_Coordination_File ---> in one variable. test ---> in one variable train ---> in one variable sun1 ---> in one variable M: ---> in one variable Regards Javeed Regards Javeed ------_=_NextPart_001_01C23FA5.9CD6ED00-- ...

Split string
I want to accept a creditcard number and display only the last 4-digit on a label. How do I split a string (or an integer) at the last 4 digits. Please help.Dim ccn as string = 1234567890123456Dim ccn2 as string = split(ccn.....??? Lable1.Text = "************" & ccn2  you can use substring to get last 4 characters of the string...Amit Malhotrahttp://www.learnlinq.blogspot.com/ STRING.SubString(0, 1) 0 being the first character and 1 being how many characters you want to grab FROM the first character The String data type in .NET is pretty powerful, you should check out ...

splitting a string
Hi: I want to split the string 0.0.0.0.1.10.1.30.1.10.1.30.1 into 4 variables: 0.0.0.0, 1, 10.1.30.1 and 10.1.30.1 any suggestions? TIA ravi __________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ On Dec 10, 2003, at 4:49 PM, Ravi Malghan wrote: > Hi: I want to split the string > 0.0.0.0.1.10.1.30.1.10.1.30.1 > > into 4 variables: 0.0.0.0, 1, 10.1.30.1 and 10.1.30.1 > > any suggestions? yes, get better data. a part of the problem you have is the that you could do this wit...

Web resources about - Split String - sybase.powerscript

SNL Presents ‘A Hillary Christmas’ with Amy Poehler and Tina Fey: WATCH
Hillary Clinton goes to bed on Christmas eve dreaming of her election to President of the United States and is visited by ghosts of Christmas ...

Suspected bomb forces Air France flight to land in Kenya; 6 passengers questioned
Los Angeles Times Suspected bomb forces Air France flight to land in Kenya; 6 passengers questioned Los Angeles Times A Kenyan police official ...

Terrorist Tashfeen Malik’s Visa Application ‘Sloppily Handled:’ Congressman
Tashfeen Malik, one of the terrorists in the San Bernardino shooting, got into the U.S. partially thanks to a “sloppily handled” visa application, ...

Auburn Deputy Mayor Salim Mehajer to be charged with electoral fraud offences
Controversial Auburn City Council Deputy Mayor Salim Mehajer is served with a court attendance notice for alleged electoral fraud offences.

South China Sea- Other countries shouldn’t meddle: Chinese envoy
BJP general secretary Ram Madhav and Chinese ambassador Le Yucheng shared opposing views on the contentious issue of South China Sea on Saturday. ...

'Remember his name': Knoxville teen killed by gunfire praised for sacrifice
Knoxville News Sentinel 'Remember his name': Knoxville teen killed by gunfire praised for sacrifice Knoxville News Sentinel Zack Dobson, bottom ...

Landslide buries buildings in southern China; 27 missing
Fox News Landslide buries buildings in southern China; 27 missing Fox News BEIJING – A landslide collapsed and buried buildings at and around ...

Introducing 2015’s Miss World Winner: Miss Spain, Mireia Lalaguna Royo
Miss World winner 2015 is Mireia Lalaguna Royo, who won the title of Miss Spain before competing in the global competition. She is a 23-year-old ...

Arsenal given green light to chase Chelsea target Marcelo Brozovic following Jose Mourinho sacking
Marcelo Brozovic has emerged as an Arsenal target following Jose Mourinho's sacking.

Kurt Masur, music director emeritus of the New York Philharmonic orchestra, dies at 88
Masur was instrumental in bringing order to the New York Philharmonic orchestra.

Resources last updated: 12/20/2015 2:56:01 PM