2016-07-28 60 views
-1
Sub SaveInLogs(isThereNewLogs As Boolean, value As String) 

    Dim list As List(Of String) 
    Try 
     list = Strings.Split(value, "#-!-#").ToList 
     list(2) = "Incoming" 
     For Each word In list 
      MsgBox(list) 
     Next 
    Catch ex As Exception 
    End Try 

End Sub 

paramater「價值」的價值是這樣的:! 2016年7月28日上午10時19分27秒# - - #Alex17282016# - !###1ST我希望有額外的字符將作爲分隔我串

然後我分割這些值並將單詞Outgoing改爲Incoming。

現在我想讓我的字符串再次看起來像這樣 2016/7/28 10:19:27# - ! - #Alex17282016# - ! - #Incoming# - ! - #Alex# - ! - # Alex# - ! - #Text# - ! - #1ST

對不起,我的語法。我希望你明白我的問題

+0

爲什麼在第一個位置分割字符串? [String.Replace]有什麼問題(https://msdn.microsoft.com/en-us/library/windows/apps/fk49wtc1(v = vs.105).aspx)? –

+0

爲什麼不使用JSON?這更簡單實用。只是一個建議。 –

+0

我不完全確定你在問什麼,但也許''''''''''' – Mark

回答

0

下面我編輯你的代碼已經使字符串的方式,你希望它改變後,「呼出」到「來電」:

Sub SaveInLogs(isThereNewLogs As Boolean, value As String) 

Dim list As List(Of String) 
Dim newValue as String = "" 
Try 
    list = Strings.Split(value, "#-!-#").ToList 
    list(2) = "Incoming" 

    For Each word In list 
     newValue = newValue & word 
    Next 

    value = newValue 
Catch ex As Exception 
End Try 

End Sub 

或者馬克在評論說,你可以使用,而不是一個循環的string.join:

Sub SaveInLogs(isThereNewLogs As Boolean, value As String) 

Dim list As List(Of String) 
Try 
    list = Strings.Split(value, "#-!-#").ToList 
    list(2) = "Incoming" 

    Dim newValue As String = String.Join("#-!-#", list) 

Catch ex As Exception 
End Try 

End Sub 

下面是代碼,我覺得會更好地工作,因爲它是一個一行代碼,也不需要來拆分字符串,並把它回到一起:

Sub SaveInLogs(isThereNewLogs As Boolean, value As String) 

    value = value.replace("#-!-#Outgoing#-!-#", "#-!-#Incoming#-!-#") 

End Sub 
相關問題