Jump to content

Remove text from string


Recommended Posts

Hello

Is it possible to remove the comment like the one on the screenshot? Remove everything from /* untiltil */

I'm going to use the text to run a state machine. And also let the user make comments in the "code"

post-3560-1159888534.png?width=400

And a second question: It it possible to color the comment when viewed on the screen? Like on the second screenshot? (The text in green)

post-3560-1159888545.png?width=400

Link to comment
Hello

Is it possible to remove the comment like the one on the screenshot? Remove everything from /* untiltil */

I'm going to use the text to run a state machine. And also let the user make comments in the "code"

Use match reguar expression node and cofigure it so that it matches the things you want to remove. Then run it in a loop as long as it matches something. To learn regular expressions check this very good web site.

Link to comment
And a second question: It it possible to color the comment when viewed on the screen? Like on the second screenshot? (The text in green)

post-3560-1159888545.png?width=400

Your second question (syntax highlighting) made me wonder - has anyone successfully developed a syntax-highlighting text control in LabVIEW? Scintilla is an editor component used in a whole bunch of open source text-based projects. There is an ActiveX control wrapper for it here - has anyone used this? I downloaded it and tried it briefly, but using it wasn't as intuitive as I thought it would be, and I don't have time to pour through the documentation right now.

Of course, a LabVIEW application which includes a C/C++ (or any text-based language, for that matter) syntax highlighter is probably the last thing most of us LabVIEW freaks would ever want to see :laugh: , but this could actually be useful (our big project includes a scripting component, for which a syntax highlighting editor could be useful).

... On second thought, maybe building a LV-based IDE for text-based source code editing (like SciTE, CodeBlocks, Dev-C++, Jedit, etc.) would be a great marketing tool for LV :D

Jaegen

Link to comment

Hi,

I just took a quick look at your solution, and I think you can make this even easier.

1. Enable "Replace All" option and skip the loop.

2. remove the \ to cancel special interpretation of / (at the beginning and at the end of the search string)

I made a quick implementation to colorize your comments, to give you an idea how it can be done.

Hope it works :blink:

Download File:post-5958-1159977170.vi

/J

Edit: I updated the attachment so that it is saved in LV8 instead of LV8.20, sorry...

Thanks guys I worked it out with the "Search and Replace String" function.

The regular expression to remove CSS-style comments is : /\*[^*]*\*/ :ninja:

Link to comment
Hi,

I just took a quick look at your solution, and I think you can make this even easier.

1. Enable "Replace All" option and skip the loop.

2. remove the \ to cancel special interpretation of / (at the beginning and at the end of the search string)

I made a quick implementation to colorize your comments, to give you an idea how it can be done.

Hope it works :blink:

Download File:post-5958-1159977170.vi

/J

Edit: I updated the attachment so that it is saved in LV8 instead of LV8.20, sorry...

Fantastic :thumbup: yes that made my code easier :)

Your color the comments vi worked great when run once, but I'm aiming at updating the colouring when typing.

Maybe an event structure is the way to go.

But as you see in my attachment it constantly marks all the text, and then the user deletes what he has already typed in.

Download File:post-3560-1159979520.vi

Link to comment

The problem is that you have to set the selection in order to set color.

After the loop is done, set the text selection to the next write position.

If you are going to edit a lot of text, you will have to come up with a clever scheme to reduce updates, timing maybe?

Download File:post-5958-1159980405.vi

/J

Fantastic :thumbup: yes that made my code easier :)

Your color the comments vi worked great when run once, but I'm aiming at updating the colouring when typing.

Maybe an event structure is the way to go.

But as you see in my attachment it constantly marks all the text, and then the user deletes what he has already typed in.

Link to comment
The problem is that you have to set the selection in order to set color.

After the loop is done, set the text selection to the next write position.

If you are going to edit a lot of text, you will have to come up with a clever scheme to reduce updates, timing maybe?

Download File:post-5958-1159980405.vi

/J

Yes, maybe something like a countdown after each value change before updating, and each new valuechange resets the countdown.

Link to comment
  • 3 weeks later...

I'm glad people are using the regular expression features. It makes me happy. :)

Here's another regexp that may or may not perform better (I'll leave benchmarks as an exercise to the reader) :

\/\*([^*]|(\*(?!\/)))*\*\/

It says "match /*, followed by a non-* or a * that is not followed by /, followed by /*". The ?! is a "negative lookahead" match. You can find more info the "definitive" reference for Perl-Compatible regular expressions here: http://www.perl.com/doc/manual/html/pod/perlre.html

These are all nice. Since there are still a lot of people and projects using LabVIEW 7.1, it might be nice to repost in 7.x.

The regular expression feature was added in 8.0. If you want to do this in a pre-8.0 version of LabVIEW, then you'll have to write a simple parser to strip comments.

Not that this would be a terrible thing. Regular expressions are great for simplicity of code and for writing validation code, etc., but they're usually very inefficient. For simple parsing problems (like this one), a well-written straight-through parse routine would perform far better.

In fact, if this application is likely to deal with large amounts of text, then I would recommend rewriting the parser for performance reasons. Just be careful to get it right. :)

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.