-
Posted by bellah on Sun, 20 Feb 2011 00:49:12
Hi all,
I am looking for a way to find / replace a TAB (\t) char in a string.
The patterns in string.gsub only let me detect the whitespace characters class. I do not want to replace spaces, just tabs.
A general Google search didn't give me anything useful. Supposedly
string.gsub(strText, "\t', "|")
orstring.gsub(strText, "<insert a tab here>', "|")
should work, but they don't.I haven't yet found a pattern that says "all whitespace characters except space" either.
Do you know of a way?
Tia,
Rob.
-
Posted by jnwhiteh on Sun, 20 Feb 2011 09:04:41
Hi all,
I am looking for a way to find / replace a TAB (\t) char in a string.
The patterns in string.gsub only let me detect the whitespace characters class. I do not want to replace spaces, just tabs.
A general Google search didn't give me anything useful. Supposedly
string.gsub(strText, "\t', "|")
orstring.gsub(strText, "<insert a tab here>', "|")
should work, but they don't.Yes they do.
foo = "monkey\tapple\tbanana" print(#foo) -- 19 bar = foo:gsub("\t", "TAB") print(#foo) -- 23 print(bar) -- monkeyTABappleTABbanana
That's how you do it.
I haven't yet found a pattern that says "all whitespace characters except space" either.
There isn't one, and there doesn't really need to be. That would be WAY too 'special purpose' when you can already do this on your own.
Hope that helps.
-
Posted by bellah on Sun, 20 Feb 2011 13:28:23
Thanks for that one.
It didn't help me much, unfortunately.
If I use the snippet as you gave it, it works, even if I replace the \t with "real" tabs. If I read the same string from a text box in the WoW UI (as is the case for the addon), it doesn't work anymore.
Is there anything in that area that I could look at?
-
Posted by jnwhiteh on Sun, 20 Feb 2011 16:28:06
Tabs are not supported by WoW.. so I am afraid I am confused. Also, \t IS a real tab.. so I have no idea what you're talking about.
\t embedded in a Lua string is the tab character.. there is nothing else.
What precisely are you trying to do?
-
Posted by bellah on Sun, 20 Feb 2011 22:58:13
I'm trying to parse a copied text (eqdkp standings) into a table
example table: http://www.low-landers.nl/dkp/listmembers.php
addon in question: whisperloot3.googlecode.com (core.lua, line 1253)
I copy the table from the website into the text box in the addon. I then parse the data. The tabs in the copied string are column separators on the web page. I am trying to use them as such to separate out column values, as not all values are present all the time.
-
Posted by jnwhiteh on Sun, 20 Feb 2011 23:31:33
Then I suspect the data isn't appearing as you think it is. Store it in a string and parse it character by character to see what is actually there. The only real thing you have to worry about is the presence of the vertical bar (pipe) character. Anytime that appears in a chat frame edit box it gets doubled.
Unfortunately I don't have time to look into all of the details of what you're trying to do.. but as you can see.. performing gsubs and other pattern matching on tabs most certainly works, which means if its not working its either the algorithm.. or the data is not what you think it is. You can test both of these, I can't =)
-
Posted by bellah on Mon, 21 Feb 2011 20:13:53
I hadn't yet copied the data back out of the text box again to see what's actually in there. Will try that next.
Will try the char-by-char. Thanks for that (and, yes, perhaps it's the algorithm :)
EDIT
Major bummer. Wow actually expands the tabs when text is copied from the web site into the text box. Back to the drawing board it is...
-
Posted by jnwhiteh on Tue, 22 Feb 2011 12:24:46
Like I said, the widgets don't support tabs. Perhaps you could get the php page to actually output something reasonable, like CSV?
-
Posted by bellah on Tue, 22 Feb 2011 19:38:32
Trying Getdkp next, it has a server-side script that outputs a Lua string that can be directly parsed with loadstring()
Thanks for the pointers so far :)