473,699 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
Jun 27 '08 #1
14 1788
sp***********@g mail.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
Jun 27 '08 #2
On 10 Jun, 10:14, spreadbett...@g mail.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~
You say: "the data is only delimited by a comma."
But the data you show us has no commas??

Please can you clarify this?
Jun 27 '08 #3
sp***********@g mail.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.
js*******@attgl obal.net
=============== ===

Jun 27 '08 #4
sp***********@g mail.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('~',$th eString);
for ($i=0; $i<count($first ); $i++) {
$final[$i] = explode(',', $outer[$i]);
}

This gives a 2-D array for final.
Jun 27 '08 #5
On 10 Jun, 13:59, spreadbett...@g mail.com wrote:
Sorry about the confusion , was in a rush when posted it

The string data I want to split is in the format

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~

Separated by tildes ~ not commas :(

Basically need to do what Jerry says explode it and take every 5 items
as a separate array , I'll take a look at sheldonig's example if I'm
assuming correctly tat $first would be 5 in my case ?

Thanks for al the posts and sorry again for the confusion with the
commas
sheldonlg's one won't work, because he was assuming that there were
some commas.

I would do an initial explode and then use array_slice()
http://uk.php.net/manual/en/function.array-slice.php to get my chunks
of 5.
Jun 27 '08 #6
Thanks Captain, I tried array_slice but it's does exactley what it
says on the tin and just slices off a part of the array, doesn't
actually put it anywhere useable, I'm sure I need to use count
somewhere along the line
Jun 27 '08 #7
Thanks again captain I was looking through the other array functions
on the php.net site and found exactly what I need in array_chunk.
Seems to do just what I needed
Jun 27 '08 #8
On 10 Jun, 15:24, spreadbett...@g mail.com wrote:
Thanks again captain I was looking through the other array functions
on the php.net site and found exactly what I need in array_chunk.
Seems to do just what I needed
array_slice() would have worked, but you are right, array_chunk() is
exactly what you need.
Jun 27 '08 #9
..oO(sp******** ***@gmail.com)
>Thanks Captain, I tried array_slice but it's does exactley what it
says on the tin and just slices off a part of the array, doesn't
actually put it anywhere useable
Have you actually read the manual entry? array_slice() returns the
extracted part.

Micha
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
18956
by: Adam Parkin | last post by:
Hello all, I am seeking some help with the following problem. I'm working on an application where I have a resource file, and in this resource file what I want to store is a list of file names (that is, essentially a string array). The potential solutions I see are: 1) Convert the string array into one big string with each element separated by some special value, store that string into the resource file's string table as a single...
5
3239
by: Ann Marinas | last post by:
Happy New Year to all! :D I am currently developoing an application that imports data from a CSV file. Each comma represents an array item that I need to extract data with. My problem is this... I am encountering a string that has the example below: a, b, c. "d,e,f,g", abcdef
1
1715
by: Guadala Harry | last post by:
I have a string that must be split out into a string array. The segment delimiter is like this: {flag:xxx} and the "xxx" part is unknown ahead of time (can be just about any character AND any number of characters (at least one). Here is a valid sample: string sStartWithThis = "this goes to element one {flag:x} this goes to element 2 {flag:pxedqr} this goes to element 3 {flag:pzf} this goes to element 4.
20
3704
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up the data to assign each value to its own variable. So right now I am just saving the data to a txt file and when I look in the text file all the data is there. Not sure if this matters but when I open the text file in Word pad (Rich Text) It...
1
1366
by: Gustav | last post by:
Hi! I use a regex (?<!\\?)('|\\+|:) to split a string to a String. The String i get after splitting is correctly splitted but contains all the delimiters i use to decide where the string should be splitted. Do I have to loop through the array and find every index containing a single delimiter or is there a easier way to do this.
10
2730
by: klineb | last post by:
Good Day, I have written and utility to convert our DOS COBOL data files to a SQL Server database. Part of the process requires parsing each line into a sql statement and validting the data to keep the integrity of the database. We are parsing roughl 81 files and range in size 1 kb to 65 MB files (Average of 400,000 lines in the larger files). I have written this utility with VB.NET 2003 and when I parse all of the files I run out...
13
1981
by: Pedro Pinto | last post by:
Hi there. I'm trying to do the following. I have a string, and i want to separate it into other halves. This is how it should be: char string = "test//test2//test3"; were // is the part were i want to separate it and store on a
2
3267
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to lines it worked quite well but srttok isnot working for multiple blank or commas. Can strtok do this kind of splitting if it cant what should i use . Unal
0
8685
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8613
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8908
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7745
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.