码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2016-11-22 17:24:04      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:rect   wro   please   获取   lease   格式   后缀   style   发布   

在网上看到了三道测试开发的笔试题,答案是用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 ---

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

标签:rect   wro   please   获取   lease   格式   后缀   style   发布   

原文地址:http://www.cnblogs.com/good-time/p/6089758.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!