试图分开一根用线隔开的线;VB.NET
我正在编写一个音乐转置应用程序(在简单的VB控制台中),我希望该程序能够将一串不同的音符分割开来,并用;'s、 看起来像这样:试图分开一根用线隔开的线;VB.NET,vb.net,string,console,console-application,Vb.net,String,Console,Console Application,我正在编写一个音乐转置应用程序(在简单的VB控制台中),我希望该程序能够将一串不同的音符分割开来,并用;'s、 看起来像这样: 'C blues scale Dim strNotesString As String = "C; Eb; F; F#; G; Bb" Dim strTmpNotes() As String = strNotesString.Replace(" ", "").Split(";"c) 有人能推荐一种我可以实现这一目标的方法吗?我会把每个单独的音符放入一个数组中 Di
'C blues scale
Dim strNotesString As String = "C; Eb; F; F#; G; Bb"
Dim strTmpNotes() As String = strNotesString.Replace(" ", "").Split(";"c)
有人能推荐一种我可以实现这一目标的方法吗?我会把每个单独的音符放入一个数组中
Dim strTmpNotes() As String
strTmpNotes(0) = "C"
strTmpNotes(1) = "Eb"
'And so on
提前谢谢
尼克检查方法
检查方法
使用String.Split:
Dim strNotesString As String = "C; Eb; F; F#; G; Bb"
Dim strTmpNotes() As String = strNotesString.Split("; ")
使用String.Split:
Dim strNotesString As String = "C; Eb; F; F#; G; Bb"
Dim strTmpNotes() As String = strNotesString.Split("; ")
也许是这样的:
'C blues scale
Dim strNotesString As String = "C; Eb; F; F#; G; Bb"
Dim strTmpNotes() As String = strNotesString.Replace(" ", "").Split(";"c)
您还可以使用正则表达式:
Dim strTmpNotes() As String = New Regex(";\s*").Split(strNotesString)
我喜欢后者。可能是这样的:
'C blues scale
Dim strNotesString As String = "C; Eb; F; F#; G; Bb"
Dim strTmpNotes() As String = strNotesString.Replace(" ", "").Split(";"c)
您还可以使用正则表达式:
Dim strTmpNotes() As String = New Regex(";\s*").Split(strNotesString)
我更喜欢后者。非常简单的解决方案,因为.NET内置了这种功能
strTmpNotes = strNotesString.Split(';')
然后使用for循环对结果数组中的每个字符串进行修剪。非常简单的解决方案,因为.NET内置了此功能
strTmpNotes = strNotesString.Split(';')
然后使用for循环对结果数组中的每个字符串进行修剪