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



Hi:


```
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?

You should use:

static bool is_empty(string? str) {


By adding the '?' after the variable type, you say Vala compiler that it
can be NULL. If you don't put that, the Vala compiler will include a
NON-NULL check at the begining, which is what is showing that message.



--
Nos leemos

RASTER (Linux user #228804)
raster rastersoft com http://www.rastersoft.com



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