Ask Your Question
0

Scan string for unicode character

asked 2019-05-09 17:04:20 +0200

homefire gravatar image

LO Calc is entering a Unicode apostrophe in manual text entries, rather than an ASCII apostrophe which I need for exporting in a GPX file going to Garmin Basecamp. I can change this using the menu item Tools>Autocorrect options, but this is not reliable for someone else using the spreadsheet. Using a macro, I need to scan for the Unicode character U+2019, and replace it with the ASCII apostrophe. What is a good approach for this?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2019-05-09 17:50:30 +0200

Lupp gravatar image

updated 2019-05-09 18:04:59 +0200

Code:

Sub doIt()

doc0 = ThisComponent
rd   = doc0.Sheets(0).createReplaceDescriptor()
rd.SearchRegularExpression = True
rd.SearchString  = "\u2019"
rd.ReplaceString = "'"

For Each sheet In doc0.Sheets
 sheet.ReplaceAll(rd)
Next sheet

End Sub

There seems no longer to be a difference between createSerachDescriptor and createReplaceDescriptor.
You can also do it via the dispatch helper (slot machine). The code you can record to do it that way is much longer, however.

edit flag offensive delete link more

Comments

(Originally by @homefire Concerted from an answer to a comment.)
Simple Regular Expression. Thank you.

Lupp gravatar imageLupp ( 2019-05-11 20:44:44 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-05-09 17:04:20 +0200

Seen: 26 times

Last updated: May 09