如果我运行下面的代码,$SRN可以编写为输出或添加到另一个变量,但是尝试包含另一个变量或常规文本会导致它从行的开头被覆盖。我假设这与我最初分配$autocode和$SRN的方式有关,但不知道它想要做什么。
# Load the property set to allow us to get to the email body.
$item.load($psPropertySet) # Load the data.
$bod = ($item.Body.Text -creplace '(?m)^\s*\r?\n','') -split "\n" # Get the body text, remove blank lines, split on line breaks to create an array (otherwise it is a single string).
$autocode = $bod[4].split('-')[2] # Get line 4 (should be Title), split on dash, look for 3rd element, this should contain our automation code.
$SRN = $bod[1] -replace 'ID: ','' # Get line 2 (should be ID), find and replace the preceding text.
# Skip processing if autocode does not match our list of handled ones.
if ($autocode -cin $autocodes)
{
write-host "$SRN $autocode"
write-host "$autocode $SRN"
write-host "$SRN test"
$var = "$SRN $autocode"
$var
}代码会导致这样的结果,您可以看到,如果$SRN不在行的开头,那么就可以了。不确定额外的空间是从哪里来的:
KRNE8385
KRNE SR1788385
test8385
KRNE8385我希望看到这样的情况:
SR1788385 KRNE
KRNE SR1788385
SR1788385 test
SR1788385 KRNE发布于 2018-05-29 17:58:55
LotPings指出了正确的路径,这两个变量都有"0D“或"\r”。我的regex替换只是在空行上删除它们,我只在"\n“上拆分数组。将原始代码中的第3行更改为下面的代码似乎解决了这个问题。第一次看到格式-十六进制,但它似乎是最好的疑难解答这样的问题。
$bod = ($item.Body.Text -creplace '(?m)^\s*\r?\n','') -split "\r\n"https://stackoverflow.com/questions/50588241
复制相似问题