本文介绍了从vb.net中的字符串中提取字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正忙于过去的考试文件,准备下周的vb.net考试。我遇到的问题如下。
I am busy working on past exam papers in preparation for my vb.net exam next week. The question I am struggling with is as follows.
取一个长字符串的字母字符和特殊字符
将字母字符提取到string1并提取特殊字符to string2
Take in a long string of alphabetical characters and special charactersextract the alphabetical characters to string1 and extract special characters to string2
所以字符串hello:// thisismystring !?必须显示如下
so the string hello://thisismystring!? must be displayed as follows
string1 = hellothisismystring
string2 = ://!?
我的问题是这个如何从字符串中提取字符并将它们存储在变量
My question is this how do I extract characters from a string and store them in a variable?
推荐答案
一种Unicode兼容,干净和容易的方法。
One way that is Unicode-friendly, clean and easy.
Imports System.Text
Module Module1
Sub Main()
Dim sValue As String = "hello://thisismystring!?"
Dim a As New StringBuilder
Dim b As New StringBuilder
For Each c As Char In sValue
If Char.IsLetter(c) Then
a.Append(c)
Else
b.Append(c)
End If
Next
Dim s1 As String = a.ToString()
Dim s2 As String = b.ToString()
End Sub
End Module
这篇关于从vb.net中的字符串中提取字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!