Alex Alex - 4 months ago 11
Vb.net Question

I want to have extra characters that will serve as divider my to string

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


The value of paramater "value" is this :
7/28/2016 10:19:27 AM#-!-#Alex17282016#-!-#Outgoing#-!-#Alex#-!-#Alex#-!-#Text#-!-#1ST

Then I split the values and change the word Outgoing to Incoming.

Now I want my string to to look like this again
7/28/2016 10:19:27 AM#-!-#Alex17282016#-!-#Incoming#-!-#Alex#-!-#Alex#-!-#Text#-!-#1ST

Sorry for my grammar. I hope you understand my question

Answer

Below I have edited your code you already have to make the string the way you want it after changing "Outgoing" to "Incoming":

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

Or as Mark in the comments stated you could use string.join instead of a loop:

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

Below is code I think would work better, as it does it one line of code and doesn't need to split the string apart and put it back together:

Sub SaveInLogs(isThereNewLogs As Boolean, value As String)

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

End Sub