識用Visual Basic 2005 請進,只差少少程式語言…

2007-09-27 8:51 pm
請先看這個 : http://hk.geocities.com/jason10312008/Lab3.6.doc
括號內該打甚麼才能造到Lab3.6的效果?

Dim fullName, firstName, lastName As String
Dim n As Integer
fullName = txtName.Text
n = fullName.IndexOf(" ")
firstName = fullName.Substring( )
lastName = fullName.Substring( )
更新1:

With lstResults.Items .Clear() .Add("First name: " & firstName) .Add("Your last name has " & _ lastName.Length & " letters.") 剛才打打不哂,現補充。 感激不盡。

回答 (2)

2007-09-28 8:31 am
✔ 最佳答案
Substring has two overload functions:
Substring(startIndex, length)
Substring(startIndex)

firstName = fullName.Substring(0, n).Trim()
lastName = fullName.Substring(n + 1).Trim()

n is the index of the space, lastName begins at one position after n.
The Trim() function removes any white space at both ends of the string. If the are two spaces between first and last name, the extra space will be removed.
2007-09-28 3:47 am
firstName = fullName.Substring( 0,n)
lastName = fullName.Substring(n, fullName.length-n)


收錄日期: 2021-04-26 13:12:59
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070927000051KK01074

檢視 Wayback Machine 備份