I have code that adds a space after a period, if one does not exist. (ta is a textarea)
(sometext.sometext to some text. sometext)
This code in 2019r1.1 and 2019r2 works
For q As Integer = 0 To Len(ta.Text) - 1
If ta.Text.Mid(q, 1) = “.” And ta.Text.Mid(q+ 1, 1) <> Chr(32) Then
ta.Text = Replace( ta.Text, ta.Text.Mid(q, 2), ". "+ Right(ta.Text.Mid(q, 2), 1) )
End If
Next
This code in 2019r2 does not work
For q As Integer = 0 To ta.Value.Length - 1
If ta.Value.Middle(q, 1) = “.” And ta.Value.Middle(q+ 1, 1) <> Chr(32) Then
ta.Value = Replace( ta.Value, ta.Value.Middle(q, 2), ". "+ ta.Value.Middle(q, 2).Right( 1) )
End If
Next
If I replace Middle with Mid in line 2 and 3 in the R2 code it works. What is the problem with Middle?
For the sake of help, here is an API2 function to do the intended processing.
You can use it in your example as ta.Value = DotSpacing(ta.Value)
Public Function DotSpacing(txt As String) as String
Var orig() As String = txt.Split("")
Var res() As String
For i As Integer = 0 To orig.LastRowIndex
If i < orig.LastRowIndex And orig(i) = "." And orig(i+1) <> " " Then
res.AddRow ". " // stream a dot + space
Else
res.AddRow orig(i) // stream the char
End
Next
Return String.FromArray(res, "") // I wish it was a consistent: res.Join("")
End Function
I don’t know your use case, but have in mind that something like “I was there.He paid $7.00 for a coffee.” becomes “I was there. He paid $7. 00 for a coffee.”
there are many chnages like this where things moved from being 1 based to 0 based
you need to review all the chnages to make sure you have handled these properly
Here is a pattern that takes care of the dot-as-decimal problem by ignoring dots that are followed by a digit, and also ones that are followed by another dot:
Sometimes it creeps in. I knew that R2 was going to include BeginsWith for strings, as String.BeginsWith started appearing in the documentation dropdown when I was entering String. This was earlier in the summer before R2 was released.