Folks,
I have the following string:
1P,2G,3G,3ML,4L,5LB,4P
Anybody know how I can easily seperate the letters and numbers in to
multi-dimension array so as I have something like
$myarray[0][0]="1";
$myarray[0][1]="P";
$myarray[1][0]="2";
$myarray[1][1]="G";
$myarray[2][0]="3";
$myarray[2][1]="G";
$myarray[3][0]="3";
$myarray[3][1]="ML";
$myarray[4][0]="4";
$myarray[4][1]="L";
$myarray[5][0]="5";
$myarray[5][1]="LB";
$myarray[6][0]="4";
$myarray[6][1]="P";
All help via newsgroup would be much appreciated...
Thanks,
Randell D. 4 1942
On Mon, 02 Feb 2004 23:12:25 +0000, Reply-Via-Newsgroup wrote: Folks,
I have the following string:
1P,2G,3G,3ML,4L,5LB,4P
Anybody know how I can easily seperate the letters and numbers in to multi-dimension array so as I have something like
$myarray[0][0]="1"; $myarray[0][1]="P";
$myarray[1][0]="2"; $myarray[1][1]="G";
[ snip ]
[Untested...]
$string = '1P,2G,3G,3ML,4L,5LB,4P';
$init_array = explode(',', $string);
$i = 0;
foreach ($init_array as $init_element) {
preg_match(
'#^([0-9]+)([a-zA-Z]+)$#',
$init_element,
$final_array[$i]
);
$i++
}
$final_array should be a as requested if I'm thinking straight =)
All help via newsgroup would be much appreciated...
HTH.
Regards,
Ian
--
Ian.H
digiServ Network
London, UK http://digiserv.net/
Try this code:
[SNIP]
function str_sep(&$val,$key)
{
$val = preg_split('/(?<=\d)(?=\w)/', $val);
}
$str = "1P,2G,3G,3ML,4L,5LB,4P";
$myArray = explode(',',$str);
array_walk($myArray,'str_sep');
print_r($myArray);
[/SNIP]
I guess it will do the required job.
--
Rahul Anand
"Reply-Via-Newsgroup" <re************************@all.times.com> wrote in message news:<tPATb.385419$X%5.232967@pd7tw2no>... Folks,
I have the following string:
1P,2G,3G,3ML,4L,5LB,4P
Anybody know how I can easily seperate the letters and numbers in to multi-dimension array so as I have something like
$myarray[0][0]="1"; $myarray[0][1]="P";
$myarray[1][0]="2"; $myarray[1][1]="G";
$myarray[2][0]="3"; $myarray[2][1]="G";
$myarray[3][0]="3"; $myarray[3][1]="ML";
$myarray[4][0]="4"; $myarray[4][1]="L";
$myarray[5][0]="5"; $myarray[5][1]="LB";
$myarray[6][0]="4"; $myarray[6][1]="P";
All help via newsgroup would be much appreciated...
Thanks, Randell D.
"Ian.H" <ia*@WINDOZEdigiserv.net> wrote in message
news:pa****************************@hybris.digiser v.net... On Mon, 02 Feb 2004 23:12:25 +0000, Reply-Via-Newsgroup wrote:
Folks,
I have the following string:
1P,2G,3G,3ML,4L,5LB,4P
Anybody know how I can easily seperate the letters and numbers in to multi-dimension array so as I have something like
$myarray[0][0]="1"; $myarray[0][1]="P";
$myarray[1][0]="2"; $myarray[1][1]="G";
[ snip ]
[Untested...]
$string = '1P,2G,3G,3ML,4L,5LB,4P'; $init_array = explode(',', $string);
$i = 0; foreach ($init_array as $init_element) { preg_match( '#^([0-9]+)([a-zA-Z]+)$#', $init_element, $final_array[$i] ); $i++ }
$final_array should be a as requested if I'm thinking straight =)
All help via newsgroup would be much appreciated... HTH. Regards,
Ian
-- Ian.H digiServ Network London, UK http://digiserv.net/
Many thanks for that!
"Reply-Via-Newsgroup" <re************************@all.times.com> wrote in message news:<tPATb.385419$X%5.232967@pd7tw2no>... Folks,
I have the following string:
1P,2G,3G,3ML,4L,5LB,4P
Anybody know how I can easily seperate the letters and numbers in to multi-dimension array so as I have something like
<snip> http://www.weitz.de/regex-coach/
--
"Success = 10% sweat + 90% tears"
Email: rrjanbiah-at-Y!com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: bk_kl |
last post by:
Hi,
I think the following behavior of the build in function 'split' is inconsistent.
What do you think?
>>> "".split()
>>> "".split(";")
|
by: MetalOne |
last post by:
string.split("") ==>
string.split("",",") ==>
I did not expect these to have different outputs.
I have a string with comma delimited numbers.
There can be zero or more numbers in the string...
|
by: Carlos Ribeiro |
last post by:
Hi all,
While writing a small program to help other poster at c.l.py, I found
a small inconsistency between the handling of keyword parameters of
string.split() and the split() method of...
|
by: Arjen |
last post by:
Hi All,
What I want to is using a string as PATTERN in a split function. This makes
it possible for me to change the PATTERN on one place in my script...
For example:
$separator = ";";
$line...
|
by: Holysmoke |
last post by:
Hi,
I want to split a big string by nymber of characters. for eg., if total
length of the string is 80 and I want to split by each 10 characters and get
8 lines of output.
I written a...
|
by: zealotcat |
last post by:
Hi, all:
I want to implement a function (using std::string and std::vector)
split a string contain special token into vector.
eg:
string = "alex delia john"
==>
vector = "alex";
vector =...
|
by: Grey |
last post by:
how to split the string which the separator is TAB.e.g.
string a = "abc bcd abc";
a.split('Tab');
Does it need to use some special character...which like vbTab in VB6...
Million Thanks
|
by: Grey |
last post by:
how to split the string which the separator is TAB.e.g.
string a = "abc bcd abc";
a.split('Tab');
Does it need to use some special character...which like vbTab in VB6...
Million Thanks
|
by: Atli |
last post by:
The following small HowTo is a compilation of an original problem in getting some cookie-values through different methods of string-handling.
The original Problem was posted as follows:
As...
|
by: mad.scientist.jr |
last post by:
I am working in C# ASP.NET framework 1.1 and
for some reason Regex.Split isn't working as expected.
When trying to split a string, Split is returning an array
with the entire string in element ...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |