PowerTip: Finding Letters in Strings with PowerShell

Doctor Scripto

Summary: Learn four ways to use Windows PowerShell to find letters in strings.

Hey, Scripting Guy! Question I want to find out if a string contains the letter “m.” The string is stored in the variable $a as shown here:

$a=”northern hairy-nosed wombat”

Hey, Scripting Guy! Answer Here are a variety of ways to accomplish this:

a.  [string]$a.contains(“m”)

b.  $a.contains(“m”)

c.  [regex]::match($a,”m”)

d.  ([regex]::match($a,”m”)).success

0 comments

Discussion is closed.

Feedback usabilla icon