Re: glib / String handling difficult
- From: "David Necas (Yeti)" <yeti physics muni cz>
- To: Juhana Sadeharju <kouhia nic funet fi>
- Cc: gtk-list gnome org
- Subject: Re: glib / String handling difficult
- Date: Mon, 9 Jan 2006 10:57:59 +0100
On Mon, Jan 09, 2006 at 06:52:45AM +0200, Juhana Sadeharju wrote:
>
> Hello. I have always found string handling quite difficult in C.
> It also looks like sed, awk, perl etc. cannot handle all of my
> simple needs.
Really cannot? What about...
> Now more difficult example. I need to parse "12 pages" in
> a middle of a html page. For example, sscanf("%i pages",) yields
> nothing even there is only one "<number> pages" in the file.
This looks like you want to *search* for "12 pages".
> Now I first find the "pages" and move back over the "12" but
> this is not simple.
m = re.search('\b(\d+)\s+pages\b', text)
if m:
nofpages = int(m.group(1))
else:
...
This is in python, but you can use perl, ruby or awk equally
well. In C, you can use libpcre (for example).
Note sscanf("%i pages") would succeed if it was fed with the
string "12 pages", but neither sscanf nor GScanner is a tool
for *searching* in text.
Yeti
--
That's enough.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]