使用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 ---
作者:闪耀的学士帽
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!