我有字符串值740D1E11625C89019E61D0CC我想插入" - "在每个计数5长度后的字符串中。
我正在使用
Array print in order of count and index:
$temp = array();
foreach($A as $b){
foreach($b as $c){
if(isset($tmep[$c])){
$tmep[$c]++;
}else{
$tmep[$c] = 1;
}
}
}
function SortArrayByKeyThanValue (&$pArray, $pSortMethodForKey = SORT_ASC, $pSortMethodForValue = SORT_DESC){
# check user input: sorting is not necessary
if (count($pArray) < 2)
return;
# define $k and $v as array_multisort() needs real variables, as user input is put by reference
$k = array_keys ($pArray);
$v = array_values($pArray);
array_multisort(
$v, $pSortMethodForValue,
$k, $pSortMethodForKey
);
$pArray = array_combine($k, $v);
}
SortArrayByKeyThanValue($tmep);
$B = array();
array_walk($tmep, function($occurances, $value) use (&$B){
for($i=0;$i<$occurances;$i++) $B[] = $value;
});
echo implode(',', $B);
结果
740D1-E11625C89019E61D0CC
应该是
740D1-E1162-5C890-19E61-D0CC
这是修改字符串的正确方法吗?
答案 0 :(得分:1)
您可以使用Batch
中的MoreLINQ。它也有一个Nuget package。
var test = decodeHtml("<!-- SC_OFF --><div class=\"md\"><p>Here is an <a href=\"http://example.com\">example link</a></p>\n\n<p>Here is some body text for you with <sup>superscript</sup> and a bit of <strong>boldness</strong> and some <em>italics</em>. I forgot to mention this regular link here <a href=\"http://example.com\">http://example.com</a> so don&#39;t forget that one. sometimes there can be more than one <a href=\"http://example.com\">formatted link</a> and <a href=\"http://example.com\">http://example.com</a></p>\n\n<ul>\n<li>so there you go</li>\n<li>some sample text to work with</li>\n</ul>\n\n<p><del>strikethrough</del></p>\n\n<pre><code>if(canCode){\n //lol dont kid yourself\n}\n</code></pre>\n</div><!-- SC_ON -->")
$(document.body).append(test);
var $aTags = $('div.md').find('a');
$aTags.each(function() {
var $aTag = $(this),
href = $aTag.attr('href');
$aTag.on('click',function(e) {
myfunc(href);
e.preventDefault();
});
});
function myfunc(href) {
alert(href);
}
function decodeHtml(html) {
var txt = document.createElement("textarea");
txt.innerHTML = html;
return txt.value;
}
打印
var s = "740D1E11625C89019E61D0CC";
var array = s.Batch(5, seq => new string(seq.ToArray()));
Console.WriteLine(string.Join("-", array));