[英]Working with strings in visual basic 2010
我必須在Visual Basic中創建一個名為StringWork的類。
Public Class StringWork
現在,我在名為Working的類中編寫了一個共享函數,該函數可以接受字符串或字符串和布爾值。
Public Shared Function Working(ByVal SingleString as string, optional BValu as Boolean = true)as string
if(working(SingleString))then
'The handling of the string
else if (working(SingleValue, BValue) then
'do something else with string
end if
end function
我寫的函數返回一個字符串。 是否可以訪問傳遞的字符串並編輯字符串中的字符或更改字符的位置?
您可以使用該可選參數來確定如何處理該字符串:
Public Shared Function Working(ByVal singleString as string, _
Optional bValue as Boolean = True) As String
If bValue Then
'Handle the true part manipulating the result string
Else
'Handle the false part manipulating the result string
End If
End Function
如果您像這樣調用此函數:
Dim test As String = StringWork.Working("I am Spartacus")
它將使用bValue = true調用該工作函數。
從代碼或帖子中都不清楚bValue表示什么。
在VB.NET和其他.NET語言中,字符串是不可變的。 通常,如果需要修改傳遞給方法的字符串,則將返回修改后的字符串。 但是,如果您需要它來修改參數,則可以將其指定為“ ByRef”參數,在這種情況下,您可以將其設置為指向新的字符串對象,這將影響傳遞給方法作為參數。 如果需要真正可變的字符串,則需要一個字符數組或一個StringBuilder對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.