Monday, August 5, 2019

optimization - Checking for string contents? string Length Vs Empty String



Which is more efficient for the compiler and the best practice for checking whether a string is blank?





  1. Checking whether the length of the string == 0

  2. Checking whether the string is empty (strVar == "")



Also, does the answer depend on language?


Answer



Yes, it depends on language, since string storage differs between languages.





  • Pascal-type strings: Length = 0.

  • C-style strings: [0] == 0.

  • .NET: .IsNullOrEmpty.



Etc.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...