如何避免短信中出现 ASCII 0D 0A
我有 powershell 脚本,它通过短信网关发送短信。我从 txt 文件获取消息内容,没有任何返回,但我总是收到包含内容和最后一个字符 0D 0A 的短信。我怎样才能避免这些字符? 这是我的 powershell 代码:
$path = "C:\test.txt"
$EmailAddress = "[email protected]"
$smtpServer = "123.456.789.10"
$smsGateway = "[email protected]"
$subject = "asdawadWA5556WAAA"
$body = get-content $path
[string]$stringBody = $body |out-string
send-mailmessage -From $EmailAddress -To $smsGateway -Subject $subject -Body $stringBody -Smtpserver $smtpServer
I have powershell script which sends text message through a sms-gateway. I get the message content from a txt file without any returns but I always receive text messages with the content and the last characters 0D 0A. How can I avoid this characters?
This is my powershell code:
$path = "C:\test.txt"
$EmailAddress = "[email protected]"
$smtpServer = "123.456.789.10"
$smsGateway = "[email protected]"
$subject = "asdawadWA5556WAAA"
$body = get-content $path
[string]$stringBody = $body |out-string
send-mailmessage -From $EmailAddress -To $smsGateway -Subject $subject -Body $stringBody -Smtpserver $smtpServer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 PowerShell 字符串实际上是 .NET 字符串,因此您可以使用方便的
String。 Trim
方法删除前导和尾随空白字符;其中包括0x0D
和0x0A
,即构成标准 Windows 换行短语的 ASCII 回车符和换行符。您所要做的就是将
.Trim()
调用添加到Body
参数的参数中:Since PowerShell strings are really .NET strings, you can use the handy
String.Trim
method to remove leading and trailing whitespace characters; theses include0x0D
and0x0A
, the ASCII carriage return and line feed characters that make up a standard Windows newline phrase.All you have to do is add the
.Trim()
call to the argument to theBody
parameter: