Adr*_*ian 3 .net c# linq performance
如何删除字符串中的每个第二个字符?
例如:
3030313535333635 -> 00155365
3030303336313435 -> 00036145
3032323437353530 -> 02247550
Run Code Online (Sandbox Code Playgroud)
字符串总是16个字符长,结果总是8个字符长 - 被删除的字符总是'3' - 不要问为什么然而 - 我没有想到这个疯狂的源数据.
Rah*_*thi 11
试试这个从字符串中获取其他所有字符: -
var s = string.Join<char>("", str.Where((ch, index) => (index % 2) != 0));
Run Code Online (Sandbox Code Playgroud)
String input = "3030313535333635";
String result = "";
for(int i = 1; i < 16; i +=2 )
{
result += input[i];
}
Run Code Online (Sandbox Code Playgroud)
你可以使用这个着名的类System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary
:)
string str = "3030313535333635";
var hex = System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary.Parse(str);
var newstr = Encoding.ASCII.GetString(hex.Value);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4895 次 |
最近记录: |