公告
财富商城
积分规则
提问
发文
2019-02-07 17:09发布
贼婆χ
are there a similar functions to explode/implode in the .net-framework?
or do i have to code it by myself?
String.Join and String.Split
String.Join
String.Split
The current answers are not fully correct, and here is why:
all works fine if you have a variable of type string[], but in PHP, you can also have KeyValue arrays, let's assume this one:
string[]
KeyValue
$params = array( 'merchantnumber' => "123456789", 'amount' => "10095", 'currency' => "DKK" );
and now call the implode method as echo implode("", $params); your output is
implode
echo implode("", $params);
12345678910095DKK
and, let's do the same in C#:
var kv = new Dictionary<string, string>() { { "merchantnumber", "123456789" }, { "amount", "10095" }, { "currency", "DKK" } };
and use String.Join("", kv) we will get
String.Join("", kv)
[merchantnumber, 123456789][amount, 10095][currency, DKK]
not exactly the same, right?
what you need to use, and keep in mind that's what PHP does, is to use only the values of the collection, like:
String.Join("", kv.Values);
and then, yes, it will be the same as the PHP implode method
You can test PHP code online using http://WriteCodeOnline.com/php/
String.Split() will explode, and String.Join() will implode.
最多设置5个标签!
String.Join
andString.Split
The current answers are not fully correct, and here is why:
all works fine if you have a variable of type
string[]
, but in PHP, you can also haveKeyValue
arrays, let's assume this one:and now call the
implode
method asecho implode("", $params);
your output isand, let's do the same in C#:
and use
String.Join("", kv)
we will getnot exactly the same, right?
what you need to use, and keep in mind that's what PHP does, is to use only the values of the collection, like:
and then, yes, it will be the same as the PHP
implode
methodYou can test PHP code online using http://WriteCodeOnline.com/php/
String.Split() will explode, and String.Join() will implode.