Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Finding Letters in Strings with PowerShell

$
0
0

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


Viewing all articles
Browse latest Browse all 3333

Trending Articles