将字符串拆分为数组中的数组但只有一个分隔符? [英] Splitting a string into arrays within an array but only one delimiter?

查看:117
本文介绍了将字符串拆分为数组中的数组但只有一个分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个字符串拆分成一个单独的数组,但数据只是用逗号分隔的
。实际数据是一个长字符串,但

信息是常规格式,并在每五个之后重复。

即数据可能会返回为

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~

我想我只需要循环每五个但不确定

使用php的最佳方式,用C#I猜猜我可以使用长度但是没有使用php太多线索了。目前我甚至正在考虑使用preg_replace每隔5~5更改一个分隔符,但

必须有一个更正确的方法

谢谢

解决方案

sp *********** @ gmail.com 写道:


我正在尝试拆分字符串进入一个单独的数组,但数据是仅用逗号分隔的
。实际数据是一个长字符串,但

信息是常规格式,并在每五个字母后重复。


即数据可能是返回


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~


我想我只需循环每五个但不确定

使用PHP的最佳方式,使用C#我想我可以使用长度但是没有使用php太多线索了。目前我甚至正在考虑使用preg_replace每隔5~5更改一个分隔符,但

必须有一个更正确的方法


谢谢



你能否显示源字符串,以及拆分结果?

我不喜欢不明白你的意思


6月10日,10:14,spreadbett ... @ gmail.com写道:


我正在尝试将一个字符串拆分成一个单独的数组,但数据只是用逗号分隔的
。实际数据是一个长字符串,但

信息是常规格式,并在每五个字节后重复。


即数据可能是返回为

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~



你说:数据只用逗号分隔。

但你给我们看的数据没有逗号?


请你澄清这个吗?


sp*********** @ gmail.com 写道:


我正在尝试将一个字符串拆分成一个单独的数组,但数据只是用逗号分隔的
。实际数据是一个长字符串,但

信息是常规格式,并在每五个字母后重复。


即数据可能是返回


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~


我想我只需循环每五个但不确定

使用PHP的最佳方式,使用C#我想我可以使用长度但是没有使用php太多线索了。目前我甚至正在考虑使用preg_replace每隔5~5更改一个分隔符,但

必须有一个更正确的方法


谢谢



或者爆炸()''〜''上的字符串并取每5个项目并将它们放入

他们自己的数组。


-

==================

删除x来自我的电子邮件地址

Jerry Stuckle

JDS计算机培训公司
js ******* @ attglobal.net

==================


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

解决方案

sp***********@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


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**
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?


sp***********@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.
js*******@attglobal.net
==================


这篇关于将字符串拆分为数组中的数组但只有一个分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆