Development :  K-Meleon Forum
K-Meleon development related discussions. 
String "cleaning" in macro
Posted by: Hugo
Date: January 10, 2003 11:33PM

Good day all,

I am writing a little macro in which I want to
- show a prompt() to the user, in which the *default text* is taken from what is
currently selected in the window by the user.

But the string that is currently selected might be "dirty" - include
newlines and other trash characters..

[Here's the prob:]
I would like to "clean" this string - only keep alphanumerics and spaces (and hyphens perhaps) but no trash. Any ideas?

It's probably not possible, right? Requires some simple RegExp support, I would think..

code so far:
my_macro{
$old_clip = getclipboard();
# Get currently selected:
setclipboard("");
id(ID_EDIT_COPY);
$q = getclipboard();

#Here, I do a little cleaning:
$q = gsub( "\n", " ", $q );
$q = gsub( " ", " ", $q );

# But it's not really enough.. Have only removed the \nconfused smiley.
# The same for \r won't work :-(
# The default strĂ­ng in the following prompt still gets ugly..
$strings = prompt('A prompt..', ' ..with an ugly default string: ', $q);

}

Any ideas appreciated!
/Hugo
[heh.. comp.lang.kmeleonmacros!]

Options: ReplyQuote


K-Meleon forum is powered by Phorum.