vb.net中的String.Split方法优化方式 [英] String.Split Method optimize way in vb.net

查看:388
本文介绍了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!

推荐答案

拆分将起作用..


http://msdn.microsoft.com/en-us/library/b873y76a.aspx [ ^ ]

split will work..


http://msdn.microsoft.com/en-us/library/b873y76a.aspx[^]

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方法优化方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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