Re: [Vala] How to check if string is empty



Hi Alexandre,

In Vala you can simply just check for str != "", this is enough.

Regards,
Dmitry

16.01.2017, 21:28, "Alexandre Oliveira" <xinayder airmail cc>:
I tried this in my method, even replacing 'string' for 'string?', but I
still get the same message in my terminal.

What is your suggestion to suppress these messages?

On 16/01/2017 17:23, Guillaume Poirier-Morency wrote:
 You should test for nullity before addressing the string.

     return str == null || str.length == 0;

 If you expect the string to be potentially 'null', use the 'string?'
 type instead.

 2017-01-16 14:09 GMT-05:00 Alexandre Oliveira <xinayder airmail cc
 <mailto:xinayder airmail cc>>:

     Hello!

     I've just heard about Vala and I've been messing around with it these
     past days.

     However, I came across a problem. I need to check if some strings aren't
     empty, and I realized there's no method in Vala that's equivalent to
     C#'s `string.IsNullOrEmpty(string)`.

     I tried setting up a static method to check if the given string is
     empty:
     ```
     static bool is_empty(string str) {
         return str[0] == '\0' || str == null;
     }
     ```

     However, running my code, I get the following message repeatedly in my
     terminal: ** (main.exe:2288): CRITICAL **: is_empty: assertion 'str !=
     NULL' failed

     What am I doing wrong?

     Thanks!
     --
     Alexandre Oliveira
       167F D82F 514A E8D1 2E9E
       C62D 1B63 9D4A 7E9D DA9D
     _______________________________________________
     vala-list mailing list
     vala-list gnome org <mailto:vala-list gnome org>
     https://mail.gnome.org/mailman/listinfo/vala-list
     <https://mail.gnome.org/mailman/listinfo/vala-list>

 --
 Guillaume Poirier-Morency <guillaumepoiriermorency gmail com
 <mailto:guillaumepoiriermorency gmail com>>

 Étudiant au baccalauréat en Informatique à l'Université de Montréal
 Développeur d'application web

 *Mon blog:* arteymix.github.io <https://arteymix.github.io>
 *Mon projet de coopérative:* pittoresque.github.io
 <https://pittoresque.github.io>
 *Clé PGP:* B1AD6EA5
 <https://pgp.mit.edu/pks/lookup?op=vindex&search=0x1CCFC3A2B1AD6EA5>

--
Alexandre Oliveira
  167F D82F 514A E8D1 2E9E
  C62D 1B63 9D4A 7E9D DA9D
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]