[VB.Net]快速找出控制項中有幾個斷行符號
Private Sub Form1_Shown(sender As System.Object, e As System.EventArgs) Handles MyBase.Shown
Dim lbl1 As New Label
lbl1.AutoSize = True
lbl1.Text = String.Format("{0}{1}{2}{3}", "枯藤老樹昏鴉" + vbCrLf, "小橋流水人家" + vbCrLf, "古道西風瘦馬" + vbCrLf, "夕陽西下斷腸人在天涯。")
Me.Controls.Add(lbl1)
MessageBox.Show("找到" & (lbl1.Text.Split(vbCrLf).Length - 1).ToString & "個斷行符號")
End Sub
instr 適合用在找文字在那個位置
而要找文字出現次數使用split 也許比較適合
如有錯誤 歡迎指正