SORU
6 Aralık 2012, PERŞEMBE


Nasıl bir dize null veya boş olup olmadığını kontrol edin PowerShell miyim?

Eğer bir dize null veya boş olup olmadığını kontrol etmek amacıyla inşa edilmiş-IsNullOrEmpty-gibi bir işlevi var, powershell'de?

Şimdiye kadar bulamadım ve eğer bir yerleşik bir yolu varsa, bunun için bir fonksiyon yazmak istemiyorum.

CEVAP
6 Aralık 2012, PERŞEMBE


Siz bu çok zor hale getiriyor. PowerShell bu oldukça zarif örneğin kolları:

> $str1 = $null
> if ($str1) { 'not empty' } else { 'empty' }
empty

> $str2 = ''
> if ($str2) { 'not empty' } else { 'empty' }
empty

> $str3 = ' '
> if ($str3) { 'not empty' } else { 'empty' }
not empty

> $str4 = 'asdf'
> if ($str4) { 'not empty' } else { 'empty' }
not empty

> if ($str1 -and $str2) { 'neither empty' } else { 'one or both empty' }
one or both empty

> if ($str3 -and $str4) { 'neither empty' } else { 'one or both empty' }
neither empty

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • gsmaestro

    gsmaestro

    17 AĞUSTOS 2006
  • RiceBunny

    RiceBunny

    16 ŞUBAT 2006
  • TastyTuts | Creative video tutorials by Gareth David

    TastyTuts |

    6 Temmuz 2011