Re: [Vala] Need help with string
- From: Nicolas <c r n a wanadoo fr>
- To: Abderrahim Kitouni <a kitouni gmail com>, vala-list gnome org
- Subject: Re: [Vala] Need help with string
- Date: Thu, 03 Sep 2009 12:05:48 +0200
Hi Abderrahim,
I use this:
using GLib;
public static void main(string[] args)
{
string contents;
try {
FileUtils.get_contents("test.txt", out contents);
} catch (FileError err) {
stdout.printf("error");
}
var info = contents.str("[INFO]");
if (info != null) {
var needed_text = info.substring("[INFO]".length);
stdout.printf("%s", needed_text);
}
}
and it works perfectly.
Thank you so much !
Nicolas.
Hi,
2009/9/3 Nicolas <c r n a wanadoo fr>:
That's the problem, I have a text file, but at a certain place there is, for
example, the code [INFO] and I need to read everything that comes after this
code, which in fact is just text !
Maybe you just want FileUtils.get_contents [1], it will return a
string that you can use as you like
string contents;
try {
FileUtils.get_contents(filename, out contents);
} catch (FileError) {
//handle appropriately
}
var info = contents.str('[INFO]');
if (info != null) {
var needed_text = info.substring('[INFO]'.length);
// do what you want with this
}
I haven't compiled this code, so there may be some problems with it,
but the idea is there.
HTH,
Abderrahim
[1] http://references.valadoc.org/glib-2.0/GLib.FileUtils.get_contents.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]