Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

split up text

Posted on 2000-02-24
6
Medium Priority
?
197 Views
Last Modified: 2010-03-05
if my variable contains
$myvar="this=is=a=test=string";

and i do
($x,$y)=split("=",$myvar);

then $x becomes "this"
and $y becomes "is"

but how do i split it so that
$x becomes "this"
and $y becomes "is=a=test=string";

ie $y becomes the rest of the string

thanks
0
Comment
Question by:paulwhelan
6 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 200 total points
ID: 2555149
try this...

this script in flexible in that tomorrow if you have one more = field in myvar it would still work.

Eg. try this script with $myvar="this=is=a=test=string=for=testing";
==================================================
#!/usr/local/bin/perl

$myvar="this=is=a=test=string";

$x=substr($myvar,0,index($myvar,"="));
$y=substr($myvar,(index($myvar,"=")+1),length($myvar));

print $x,"\n",$y,"\n";

0
 
LVL 1

Expert Comment

by:mrachow
ID: 2555174
There is a thirt parameter for split available.
Try
($x,$y)=split("=",$myvar,2);

Greetings.
0
 
LVL 3

Expert Comment

by:RobWMartin
ID: 2556227
Or this:

($x,@y)=split("=",$myvar);
$y=join("=",@y);

Rob
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:RobWMartin
ID: 2556237
Or this:

($x,$y)=$myvar=~/^(.+?)=(.*)/;

Rob
0
 

Author Comment

by:paulwhelan
ID: 2557215
sorry maneshr got there first....
0
 

Author Comment

by:paulwhelan
ID: 2557217
it works thats the main thing
;)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question