質問

I have a Note as stringBuilder with word and date: reval 41/50/50 I want to manipulate it, so I will have: reval 05/05/14.

(The date is only when I have the word reval before)

My function is:

Sub correctDateShowing(ByRef Note As StringBuilder)

    Dim index, i, j As Integer

    For index = 0 To Note.Length - 2
        If (Note(index).ToString = "r" And Note(index + 1).ToString = "e") Then
             For i = 6 To Note.Length - 1  'start from 6,because I want only the date to be reversed
                'Here I am Stuck!!
             Next   
        End If

    Next

End Sub

I try to do some replacing with a tmp variable but it didn't work. I will be glad to get some help.

Thanks All!!!

役に立ちましたか?

解決

Sub CorrectDateShowing(ByRef Note As StringBuilder)
    Dim str As String = Note.ToString()
    Dim arr As String() = str.Split(" "c)
    arr(1) = StrReverse(arr(1))
    Note = New StringBuilder(arr(0) & " " & arr(1))
End Sub

Split the text into two parts, reverse the second part (the date) and then reconnect them.

他のヒント

Try this:

Dim tempCharArray As char[]
Dim dateStartIndex, dateLength As int
'' Here you need to calculate the date start index and date length (i guess the date length is always 8)
Note.CopyTo(dateStartIndex, tempCharArray, 0, dateLength)
Note.Replace(new String(tempCharArray), new String(Array.Reverse(tempCharArray)), dateStartIndex, dateLength)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top