Replace 4 dots with the Ellipsis

The code below does not works as intended:


TA.Text = TA.Text.ReplaceAll("....","…")

I get the Ellipsis AND a dot…

But a ReplaceALL for three or two dots works fine.

I found in an Aussie text four consecutives dots, so I add code to modify that.

Are you sure there isn’t 5 dots? That would result in an Ellipsis and a dot. If you are looking for a way of replacing “3 or more dots” with an ellipsis then you could to use a Regular Expressions.

That is the code I Copy/Paste from the Code Editor and I typed 4 dots in both my working Xojo version and in the current one.

For RegEx: good idea, but onloy for that change ?
What is the size of the RegEx added to my application ?

If you declare the regex object and assign a property, build your application you can see what the size difference would be.

I would avoid regex if you don’t need it. Simple fixed string replacement is better done with standard string Replace an ReplaceAll, why complicate things.

In this example, for multiple series of dots to an ellipsis, it’s a good use. There are other options if you don’t want the extra lib included. Scanning the string sequentially, for example. However, avoid code like the following as string concatenation of this type is very slow.

var NewString
Foreach Char as string in MyString
   NewString = NewString + Char
Next

Especially if MyString is large. If you are doing lots of string concatenation it is very much worth changing to the code recommended in this article:

[String building in REALbasic - Boredom Software](https://String building in REALbasic)

What about:

It certainly should work. If there are only four .s and all the encodings are correct.

The encodings comments are worth looking into. Is the string in the control UTF8? The “…” and “…” should be as they are literal text and Xojo defaults to UTF8. Put a breakpoint in and check what the debugger has to say about the property. Being pasted in it could be in another encoding.

i typed the text in the application. why are you talking about encoding ? it’s only ascii (part of the default utf8)…

Only, because I can’t think of anything else that could prevent it from working.

a bug ?

Did you try the code ?

Yes, it is reproducible. Odd that the debugger claims the length of the typed string is 2. Which likely points to the issue. I think macOS is converting the … to an ellipsis as you type it. Which means that your … is actually starting out as ellipsis plus . and it isn’t the find and replace that is causing the problem.

In fact if you click out of the texture and then back in, without running any code and then use left and right arrow the ellipsis and . can be confirmed as the contents.

1 Like

As an aside type pressing - twice followed by a space. The two minuses turn into a long dash. I think it is that mechanism that is causing the change.

  • Open system preferences
  • Click on the Keyboard item.
  • Select the Text tab.
  • Turn off the Use smart quotes and dashes checkbox
  • Xojo now does what you expect.

You are correct.

The original text comes from LiveText (macOS embedded OCR feature) pasted in the TextArea (default properties) and the three dots stays as is.

I noticed a problem after I coded the replacement for 4,3 and 2 dots to the Ellipsis (sometimes I get only two dots instead of three, four dots were in Aussie texts…).

So, it is a feature, not a bug. I only have to set a replace Ellipsis + Dot to Ellipsis and I’m done on that !

I think that’s a better option than attempting to get people to change the Keyboard behaviour. :slight_smile:

Yes.

I can do that (and I’ve done that for the two spaces replaced with space+dot), but go to explain to each and every user what to do…

The list is large enough !