使用PowerShell解三道测试开发笔试题

在网上看到了三道测试开发的笔试题,答案是用Python解的。这段时间正好在学PowerShell,练习一下:)

 

1. 验证邮箱格式

2. 获取URL的后缀名

3. 获取前一天时间或前一秒

 

我的解法是:

 

 1 # Check Email format
 2 Write-Host "Please input your email address"
 3 $email=Read-Host
 4 $regular="[a-zA-Z0-9]\@[a-zA-Z0-9]\.[a-zA-Z0-9]"
 5 if($email -match $regular)
 6 { write-host "Email is correct, pass!" -ForegroundColor Green
 7 }else{
 8 Write-Host "Email is wrong, waring!" -ForegroundColor Red
 9 }
10 
11 #-------------------------------------------------------------
12 
13 # Get the URL name extensions
14 Write-Host "Please input one URL"
15 $url=Read-Host
16 $extension=($url.Substring($url.LastIndexOf(".")+1))
17 Write-Host "The URL extension is:" $extension -ForegroundColor Green
18 
19 #------------------------------------------------------------
20 
21 # Get the previous time
22 $Now=Get-Date
23 $Now.AddDays(-1)                       # Yesterday
24 $Now.AddSeconds(-1)                    # previous second

 

加油!2017!

Thanks,

Litao

 

-----发布于Tuesday, November 22, 2016 4:09:35 PM ---

posted @ 2016-11-22 16:10  闪耀的学士帽  阅读(466)  评论(0编辑  收藏  举报