Click here to get back home

Splitting a string into arrays within an array but only one delimiter ?

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Splitting a string into arrays within an array but only one delimiter ? spreadbetting 06-10-2008
Get Chitika Premium
Posted by spreadbetting on June 10, 2008, 5:14 am
Please log in for more thread options
I'm trying to split a string into an separate arrays but the data is
only delimited by a comma. The actual data is one long string but the
info is in a regular format and repeats after every five ~'s .


i.e the data may be returned as


1.01~11844.69~0.0~0.0~2.0~1.02~117.3~0.0~0.0~0.0~1.03~66.82~0.0~0.0~0.0~1.0=
=AD
4~300.0~0.0~0.0~0.0~


I guess I just have to loop through every five ~'s but unsure of the
best way using php , with C# I guess I could use length but haven't
too much of a clue using php. At the moment I'm even considering a
dirty fix using preg_replace to change the delimiter every 5 ~'s but
there must be a more correct way


Thanks

Posted by GuangXiN on June 10, 2008, 5:37 am
Please log in for more thread options
spreadbetting@gmail.com wrote:
> I'm trying to split a string into an separate arrays but the data is
> only delimited by a comma. The actual data is one long string but the
> info is in a regular format and repeats after every five ~'s .
>
>
> i.e the data may be returned as
>
>
> 1.01~11844.69~0.0~0.0~2.0~1.02~117.3~0.0~0.0~0.0~1.03~66.82~0.0~0.0~0.0~1.0­
> 4~300.0~0.0~0.0~0.0~
>
>
> I guess I just have to loop through every five ~'s but unsure of the
> best way using php , with C# I guess I could use length but haven't
> too much of a clue using php. At the moment I'm even considering a
> dirty fix using preg_replace to change the delimiter every 5 ~'s but
> there must be a more correct way
>
>
> Thanks

Can you show the source string, and the split results?
I don't understand what you meaning

Posted by Captain Paralytic on June 10, 2008, 5:58 am
Please log in for more thread options
On 10 Jun, 10:14, spreadbett...@gmail.com wrote:
> I'm trying to split a string into an separate arrays but the data is
> only delimited by a comma. The actual data is one long string but the
> info is in a regular format and repeats after every five ~'s .
>
> i.e the data may be returned as
>
> 1.01~11844.69~0.0~0.0~2.0~1.02~117.3~0.0~0.0~0.0~1.03~66.82~0.0~0.0~0.0~1.=
0=AD=AD
> 4~300.0~0.0~0.0~0.0~
You say: "the data is only delimited by a comma."
But the data you show us has no commas??

Please can you clarify this?

Posted by Jerry Stuckle on June 10, 2008, 6:13 am
Please log in for more thread options
spreadbetting@gmail.com wrote:
> I'm trying to split a string into an separate arrays but the data is
> only delimited by a comma. The actual data is one long string but the
> info is in a regular format and repeats after every five ~'s .
>
>
> i.e the data may be returned as
>
>
> 1.01~11844.69~0.0~0.0~2.0~1.02~117.3~0.0~0.0~0.0~1.03~66.82~0.0~0.0~0.0~1.0­
> 4~300.0~0.0~0.0~0.0~
>
>
> I guess I just have to loop through every five ~'s but unsure of the
> best way using php , with C# I guess I could use length but haven't
> too much of a clue using php. At the moment I'm even considering a
> dirty fix using preg_replace to change the delimiter every 5 ~'s but
> there must be a more correct way
>
>
> Thanks
>

Or explode() the string on '~' and take every 5 items and place them in
their own array.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================


Posted by sheldonlg on June 10, 2008, 6:27 am
Please log in for more thread options
spreadbetting@gmail.com wrote:
> I'm trying to split a string into an separate arrays but the data is
> only delimited by a comma. The actual data is one long string but the
> info is in a regular format and repeats after every five ~'s .
>
>
> i.e the data may be returned as
>
>
> 1.01~11844.69~0.0~0.0~2.0~1.02~117.3~0.0~0.0~0.0~1.03~66.82~0.0~0.0~0.0~1.0­
> 4~300.0~0.0~0.0~0.0~
>
>
> I guess I just have to loop through every five ~'s but unsure of the
> best way using php , with C# I guess I could use length but haven't
> too much of a clue using php. At the moment I'm even considering a
> dirty fix using preg_replace to change the delimiter every 5 ~'s but
> there must be a more correct way
>
>
> Thanks

If I understand you correctly, then:

$outer = explode('~',$theString);
for ($i=0; $i<count($first); $i++) {
$final[$i] = explode(',', $outer[$i]);
}

This gives a 2-D array for final.

Similar ThreadsPosted
splitting lines in arrays? April 10, 2005, 4:32 am
Splitting a string into three parts September 19, 2007, 3:25 pm
Accessing string arrays January 25, 2008, 3:44 pm
"Array to String Conversion" error when constructing a multi-dimensional array January 17, 2007, 3:42 am
getting values in an array of arrays February 7, 2007, 12:31 pm
multidimensional array of arrays September 27, 2007, 3:58 pm
php extension: returning array of arrays January 12, 2006, 10:39 pm
Swapping array elements from two different arrays November 10, 2007, 5:28 am
Not easy! Best way to clean an array of arrays May 30, 2008, 7:09 am
Arrays : returning a reference to an array item ?? August 11, 2004, 7:58 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap