What is the better way to check for an empty string in Delphi?

前端 未结 3 658
温柔的废话
温柔的废话 2021-01-01 13:17

A common condition that all programs should do is to check if string are empty or not.

Take the below statements:

(1)

if Len         


        
3条回答
  •  醉话见心
    2021-01-01 14:05

    Semantically they are identical and there will be no discernible performance difference. So we are left looking at clarity for the reader of the code.

    if Str='' then
    

    is the readable version in my opinion. Look at the title of your question:

    What is the better way to check for an empty string?

    In your head you view this as the empty string as opposed to the string with length 0. So write the code the way that matches your viewpoint.

提交回复
热议问题