I often start typing strings without enclosing them in quote marks, especially when using MessageBox, so I wrote my first Code Assistant to fix that.
// This script takes the current selection and wraps
// it in quote marks
Function Name () As String
Return "Wrap In Quotes"
End Function
Function CanEdit (selection As String) As Boolean
Return If(Selection = "", True, False)
End Function
Function Edit (selection As String) As String
Var line As String
Var a As String
a = Chr(34) + selection + Chr(34)
Return a
End Function
thanks for sharing.
just one thought.
it will not duplicate a quote if there is one inside the selected string.
is it the desired behavior ? I presume not …
you could start from this former xojo script (made by Kem IIRC)
Const kQuote = """"
Dim s As String
s = SelText
Dim eol As String
If s.InStr( &u0D + &u0A ) <> 0 Then
eol = &u0D + &u0A
Elseif s.InStr( &u0D ) <> 0 Then
eol = &u0D
Elseif s.InStr( &u0A ) <> 0 Then
eol = &u0A
End If
If eol <> "" Then
Dim lines() As String
lines = Split( s, eol )
s = Join( lines, kQuote + " + EndOfLine + _" + eol + kQuote )
End If
s = kQuote + s + kQuote
Dim start As Integer
start = SelStart
SelText = s
SelStart = start + 1
SelLength = s.Len - 2
I still don’t use last xojo 2022 so I cannot test it.
I wish they would put button in the bar above the code editor to get drop down menu for those Code Assistants. Since their pretty nice except the click path to them is a bit long.
Here’s the new version that will wrap selected with with quote marks and fix straight double quote marks inside the string.
// This script wraps the current selection
// in quote marks
Function Name () As String
Return "Wrap In Quotes"
End Function
Function CanEdit (selection As String) As Boolean
Return If(Selection = "", False, True)
End Function
Function Edit (selection As String) As String
Var a As String
Var b As String = Chr(34)
a = b + b + b + b
selection = selection.ReplaceAll(b, a)
a = b + selection + b
Return a
End Function