Issue
I'm learning solidity. I want to check if a memory string variable is a null, empty, or whitespaces. I understand I have to check it like this:
bytes(_content).length > 0
However, this does now cover empty whitespace. What would be the best way to check for empty whitespace? Or do you suggest that this check does not belong in s
Solution
if you convert "" to bytes you get 0x
if you convert " " to bytes you get 0x20
for each empty space, it adds another 20. for example 2 empty space
" " is 0x2020
empty string characters will always return "20" and as far as I know we could have slice operations with bytes array since solidity 6.0.0. For example
bytes test = '0xabcd'
test[2:5]; # 'abc'
Knowing this, if you have this
bytes whitespaces='0x20202020202020'
you could write a for loop, starting from 2 till the end,if the even index is 2 and odd index 0 that means you have only white spaces.
Answered By - Yilmaz Answer Checked By - Marilyn (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.