Capturing text with ANSI?

Posted by Bagelobo on Wed 04 Sep 2002 02:31 PM — 6 posts, 19,540 views.

#0
Hi, I'm new to vb scripting, and can't seem figure out how to capture text into a variable with the ANSI codes still attached. I'd like to be able to distinguish between two lines of the same text but which have different color codes. Is this possible? Any help is appreciated.
USA #1
Well... Yes and no. If actually getting the ansi along with the text is critical, then it isn't possible. Though some of use wish it was.

However, to merely distinguish between to lines like that is simple. Below the first field in the trigger is something like:

Match: [ ] on [ ]

These are color selectors, so you can set it to white on blue or whatever you want and then that trigger will only match on that color. Negative results are more of a problem, since there is currently no way to tell it match if the line is 'not' White on Black, etc., but for your purpose it should work.
Australia Forum Administrator #2
You can use GetLineInfo and GetStyleInfo (see elsewhere, including functions page) to retrieve the colour (and style) of individual parts of the line.

This is actually more useful than the ANSI codes, because (say) there were 4 lines, and the first had the ANSI code to change to red, and the trigger matched the 3rd line, then the line is in red, even though there is no code for that as such on the 3rd line.
USA #3
Hmm. Something else I didn't read. lol
#4
Ah, thanks, that GetStyleInfo seemed to do the trick. So anyways, I came up with a little bit o' code that strips the text, then inserts all the colors into it and stores it in a variable. Is there an easier/better way of doing this?

'"""""""""""""""""""""""""

Dim lcap, lnum, n, stylecount

lcap=""
lnum=0
stylecount=0
n=1

lnum=World.GetLinesInBufferCount
stylecount=World.GetLineInfo(lnum,11)

While n <= stylecount
lcap=lcap+"|"+World.RGBColourToName(World.GetStyleInfo(lnum,n,14))+"|"+World.GetStyleInfo(lnum,n,1)
n=n+1
Wend

World.Note lcap

'"""""""""""""""""""""""""
Australia Forum Administrator #5
Yes, that is pretty good. You can make it slightly tidier, but the general idea is about the best way of doing it.


Dim lcap, lnum, n

  lnum = World.GetLinesInBufferCount

  For n = 1 to World.GetLineInfo (lnum, 11)
    lcap = lcap + "|" + _
           World.RGBColourToName (World.GetStyleInfo (lnum, n, 14)) + _
          "|" + _
          World.GetStyleInfo(lnum, n, 1)
  Next

  World.Note lcap