我目前对我正在尝试的活动有疑问 问题如下:
史蒂夫希望将他所有员工的名字输入一个系统。但他有以下标准:
格式必须如下例所示:
**stevens#smith#thomas#mitchell#adams**
总结:
程序必须输入字符序列(由一个或多个确定名组成)
检查字符序列是否具有有效格式
计算并输出姓氏数量。
这是我到目前为止所做的 - 但我想知道是否有任何方法可以删除数组并使代码更简单,更容易记住。任何想法都非常感谢!
Module Module1
Sub Main()
Dim sequence As String
Dim surnamecount As Integer = 0
Dim sequencearray() As String
Console.WriteLine("Please enter a character sequence")
sequence = Console.ReadLine
If Len(sequence) >= 5 And sequence.Substring(0, 2) = "**" And sequence.Substring() Then
sequencearray = Split(sequence, "#")
sequencearray(0) = sequencearray(0).Substring(2)
sequencearray(UBound(sequencearray)) = sequencearray(UBound(sequencearray)).Substring(0, Len(sequencearray(UBound(sequencearray))) - 2)
For i As Integer = 0 To UBound(sequencearray)
Console.WriteLine(sequencearray(i))
surnamecount = surnamecount + 1
Next
Console.ReadLine()
End Sub
提前谢谢!