[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
substr() does't return null string
From: |
Denis Shirokov |
Subject: |
substr() does't return null string |
Date: |
Thu, 19 Dec 2019 18:48:23 +0200 |
hello,
( gawk 4.2.1 )
according to The GNU Awk User’s Guide ( at
https://www.gnu.org/software/gawk/manual/gawk.html#Bug-address ):
...If start is greater than the number of characters in the string,
substr() returns the null string...
the following example shows that substr() return empty string ( "" )
instead of null value:
BEGIN{
t = ""
a = substr( t, 1 )
print "DATA: " a "'"
if ( a == 0 && a == "" )
print "== NULL"
else
print "!= NULL"
}
as we see that substr() start character parameter ( 1 ) is higher than
the length of t ( 0 ).
but followed checking returned by substr() result shows that it is not
equal to null:
DATA: '
!= NULL
in my opinion current behaviour of substr() is more useful than
behaviour implemented in documentation because in my code i have some
places with like:
return substr(...) ""
exactly to prevent returning null value and always force it as the empty string
thnx
Denis
- substr() does't return null string,
Denis Shirokov <=