本文介绍了vb.net中的String.Split方法优化方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我有一个字符串 xxx1-0.1/1 yyy,ccc1,1 .我使用了split和substring.我只想得到 0.1/1 .有没有优化的方法可以做到这一点?

预先谢谢您!

Hi ! I have a string xxx1-0.1/1 yyy,ccc1,1. I used split and substring. All i want to get is the 0.1/1 only. Is there any optimize way to do this?

Thank you in advance!

推荐答案

string words = "xxx1-0.1/1 yyy,ccc1,1";

string[] split = words.Split(new Char[] { '-', ' ', ',' });

foreach (string s in split)
{

    if (s.Trim() != "")
        Console.WriteLine(s);
}




正则表达式虽然更酷(但我很讨厌编码员)

Bryce




regex is cooler though (in a nerdy i''m a coder sort of way)

Bryce


Dim s As String = "xxx1-0.1/1 yyy,ccc1,1"
Dim ans = s.Split(New Char() {"-"c, " "c})(1)
MessageBox.Show(ans)



使其功能



make it a function

Private Function getMySpecialValue(input As String) As String
  Return input.Split(New Char() {"-"c, " "c})(1)
End Function


这篇关于vb.net中的String.Split方法优化方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 06:02