Re: [Vala] Starting with Vala, problems with strings
- From: Yu Feng <rainwoodman gmail com>
- To: Diego Jacobi <jacobidiego gmail com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Starting with Vala, problems with strings
- Date: Sun, 19 Apr 2009 15:47:49 -0400
Hi Diego,
private static int my_string_handler(string str)/*no '*'*/ {
....
}
If possible use unichar, string.next_char, string.get_char, to
manipulate string is better than directly access the char by its
location because all strings are utf8 encoded.
StringBuilder sb = new StringBuilder("");
for(weak string s = str; s.get_char()!=0; s = s.next_char()) {
unichar c = s.get_char();
if(c != '+') sb.append_unichar(c);
else {
....
break;
}
}
Yu
On Sun, 2009-04-19 at 20:39 +0200, Diego Jacobi wrote:
Hi.
This may be a too much newbie question, but:
How do you access a character in a string?
private static int my_string_handler(string *str)
{
string s;
for (x = 0 ; x < str->len() ; x++)
{
if (str[x]=='+')
{
s = str->substring(0,x);
stdout.printf("plus finded at = %d, left string ist %s\n", x, s);
return 0;
}
}
return -1;
}
This prints an error saying that str is not an array.
I cant find anything on the docs an example on how to manipulate
strings char by char.
Cheers.
Diego
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]