String manipulation for cleaning word

Look at the TextInputStream class. It has a ReadLine method.

1 Like

Or ReadAll if the file isn’t that big.

1 Like

You can, just add comments to your future self, or others, to get it faster.

Federico, you, by any chance, have multi-line constructs? Like:

/* remove */ valid text /* remove */
/* remove */ valid text /* remove
remove remove
remove */ valid text /* remove */

Yes, but there’s nothing better than actually being able to read and understand your own code. :grinning:

It’s little used, but you can embed comments right in a pattern, e.g.:

(?U)(?# Make Ungreedy)/\*(?# Opening delimiter)[\s\S]*(?# Zero or more of anything)\*/(?# Closing delimiter)

Even better, you can split up complex patterns with whitespace using the (?x) switch, e.g.:

(?x)        # Free-space mode

(?U)        # Ungreedy
/\*         # Opening delimiter
  [\s\S]*   # Zero or more of anything
\*/         # Closing delimiter

Yes, there is. Being able to read any well documented code and documenting our own.

I dislike for example comments IN the pattern. I do prefer a clean pattern and proper comments outside saying what such pattern does.

I suppose a hybrid approach could be used:

Patter = ""
Pattern = Pattern + "(?U)"      # Ungreedy
Pattern = Pattern + "/\*"       # Opening delimiter
Pattern = Pattern + "[\s\S]*"   # Zero or more of anything
Pattern = Pattern + "\*/"       # Closing delimiter

You’d have to add + EndOfLine to each line though.

Sorry I didn’t understand the question. However, I need to have what you wrote in the example.

Thanks for the code , it’s perfect. Simply and elegant.

Thanks everyone for the support.
Especially to Kem Tekinay, Chay Wesley. Their code is perfect and the two work great.

Thank you.



Please mark some post as “Solution” for future visitors.

Do you have remarks starting in one line, but not ending in the same line, but next one or further?

/* sdfgsdfg

Or all them start and end in the same line

/* dgsdfgsfdg */

What I wrote WAS an example of such content.

That determines if you can read and apply the filter one line at a time or need to read all the content and apply it globally.

Why the pattern works without them.

You’re right, I missed that you were no longer using the (?x) switch.

You would have to switch to a valid comment char also. # doesn’t work with Xojo. But strangely ’ which does, doesn’t seem to work with the code box.

Disregarding the syntax error, I do prefer it solved all at once at compile time as a constant.

Const Pattern As String =  "(?U)"     _  // Ungreedy
                        +  "/\*"      _  // Opening delimiter
                        +  "[\s\S]*"  _  // Zero or more of anything
                        +  "\*/"         // Closing delimiter
1 Like

if only _ looked that good in the IDE, I would use it more.

1 Like

It can look good enough