#8705
chjfth
Member

Many thanks to your final clear reply. Now I know that EmEditor supports mixed EOL mark. And thank you for pointing out


str = document.GetLine( 1, eeGetLineWithNewLines )

can find out the EOL of line 1. (Yes, I must use 1 as first parameter instead of 0. 0 will cause script error “Invalid procedure call or argument”.

Now, I realize that I pratically don’t have to care if current text file has LF or CRLF as end-of-line marker; I can simply replace all occurence of “rn” to “n” before counting slen, then my goal is fulfilled.

So my script becomes:


' This VBScript macro do the following:
' For a block of selected text,
' * if a / is found, replace all occurance of / to .
' * else if a is found, replace all to / .
' After the macro is executed, the converted text will remain at its select state(invert-colored).

Set ds = document.selection
TextCopy = Replace(ds.Text, chr(13)+chr(10), chr(10)) 'replace rn to be one n
slen = Len(TextCopy) 'get selected text length, rn counted as only one char
posSlash = InStr(ds.Text, "/")
posBkSlash = InStr(ds.Text, "")

If posSlash>0 and (posBkSlash=0 or posBkSlash>posSlash) Then
' / in selected text and / appears before
ds.Text = Replace(ds.Text, "/", "")
ds.CharLeft True, slen 'make the new text in selected state(inverted color)
ElseIf posBkSlash>0 Then
' in selected text
ds.Text = Replace(ds.Text, "", "/")
ds.CharLeft True, slen
Else
Set WshShell = CreateObject( "WScript.Shell" )
n = WshShell.Popup( "There is no / or in your selected text. This macro can do nothing.", 0, "EmEditor Macro running", 0 )
End If

EmEditor is so great with custom script.