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

  • MisterBrightside

    MisterBright

    24 Mart 2006
  • pendrop gaming

    pendrop gami

    4 ŞUBAT 2013
  • spectragirlz16's channel

    spectragirlz

    22 Ocak 2012