PoolStringArray returns "not empty" while being empty

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By weirdo23

calling split on an empty string returns a PoolStringArray that will claim not to be empty while clearly being empty.

here is my code example:

    var nstr = ""
    print(nstr) #will not print! why?
	var strarr = nstr.split(" ",true,0)
	print(strarr) #prints [] an empty array
	print(strarr.empty()) #prints "False", claims to have contents



maybe someone can shed some light on this issue?


This actually prints an empty line.

var nstr = ""
print(nstr) #will not print! why?

Adam_S | 2020-09-12 23:57

:bust_in_silhouette: Reply From: p7f

You passed to the function allow_empty as true. This means that the PoolStringArray will have one element with the emtpy character (“” is represented by 0x00 in a string), as you are allowing for that. if you use var strarr = nstr.split(" ",false,0) you will notice it will return an empty array.

For checking that is different that an array has an empty character, and an empty array, you can do this:

var arr = PoolStringArray([])
var arr2 = PoolStringArray([""])
print(arr.size()) #prints 0
print(arr2.size()) #prints 1
print(arr.empty()) #prints true
print(arr2.empty()) #prints false

In summpary, with allow_true you are allowing empty string to be set as component of the resulting array, or at least thats what i always understood, since it seems not to be explained in documentation.