我正在使用Powershell来连接键,但是使用-NoNewLine时,Writehost给了我一个回车定界符和3行而不是一行。
我尝试了-NoNewLine以及其他各种代码集,例如
write-host -replace "[`r`n](-join(
轴承 eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5VTTBSRFE1UVROQk9FRTJNREJEUWtGR1JEazFNRGN4TlRReU9FUXpOalZFT0RZeVJEQXpSZyJ9.eyJpc3MiOiJodHRwczovL2lkZW50aXR5LmF1dGgwLWRldi5zcy5hd3MuYmNpZGFoby5jb20vIiwic3ViIjoidHFYQjEw ejVUT0ZvZ05rNDAzQmZYZkhrTkJxSVJ0UENAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vaWRlbnRpdHkuYXV0aDAtZGV2LnNzLmF3cy5iY2lkYWhvLmNvbS9hcGkvdjIvIiwiaWF0IjoxNTUzNTI2MDk0LCJleHAiOjE1NTM2MTI0OTQsImF6cCI6InRxWEIxMHo1VE9Gb2dOazQwM0JmWGZIa05C cUlSdFBDIiwic2NvcGUiOiJyZWFkOmNsaWVudF9ncmFudHMgY3JlYXRlOmNsaWVudF9ncmFudHMgZGVsZXRlOmNsaWVudF9ncmFudHMgdXBkYXRlOmNsaWVudF9ncmFudHMgcmVhZDp1c2VycyB1cGRhdGU6dXNlcnMgZGVsZXRlOnVzZXJzIGNyZWF0ZTp1c2VycyByZWFkOnVzZXJzX2FwcF9t PeIoyImIORI59k0Ee_Ay4jlSpiPT_FEdlln_ZWfcEDCPQ
我也一直在寻找Stack溢出的问题,每个人都说没有换行应该是答案
$assoc1 ="Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5VTTBSRFE1UVROQk9FRTJNREJEUWtGR1JEazFNRGN4TlRReU9FUXpOalZFT0RZeVJEQXpSZyJ9.eyJpc3MiOiJodHRwczovL2lkZW50aXR5LmF1dGgwLWRldi5zcy5hd3MuYmNpZGFoby5jb20vIiwic3ViIjoidHFYQjEw"
$assoc2 ="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udF9ncmFudHMgcmVhZDp1c2VycyB1cGRhdGU6dXNlcnMgZGVsZXRlOnVzZXJzIGNyZWF0ZTp1c2VycyByZWFkOnVzZXJzX2FwcF9t"
相反,结果集为我提供了3行代码,而不是1行。这是对powershell的限制吗?
答案 0 :(得分:1)
您可以通过这种方式加入他们...
$assoc1,$assoc2,$assoc3 -join ''
尽管这会在屏幕上显示为3行,但是由于屏幕格式的原因,它不是。
($assoc1 ="Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5VTTBSRFE1UVROQk9FRTJNREJEUWtGR1JEazFNRGN4TlRReU9FUXpOalZFT0RZeVJEQXpSZyJ9.eyJpc3MiOiJodHRwczovL2lkZW50aXR5LmF1dGgwLWRldi5zcy5hd3MuYmNpZGFoby5jb20vIiwic3ViIjoidHFYQjEw" ).Length
($assoc2 ="ejVUT0ZvZ05rNDAzQmZYZkhrTkJxSVJ0UENAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vaWRlbnRpdHkuYXV0aDAtZGV2LnNzLmF3cy5iY2lkYWhvLmNvbS9hcGkvdjIvIiwiaWF0IjoxNTUzNTI2MDk0LCJleHAiOjE1NTM2MTI0OTQsImF6cCI6InRxWEIxMHo1VE9Gb2dOazQwM0JmWGZIa05C" ).Length
($assoc3 ="cUlSdFBDIiwic2NvcGUiOiJyZWFkOmNsaWVudF9ncmFudHMgY3JlYXRlOmNsaWVudF9ncmFudHMgZGVsZXRlOmNsaWVudF9ncmFudHMgdXBkYXRlOmNsaWVudF9ncmFudHMgcmVhZDp1c2VycyB1cGRhdGU6dXNlcnMgZGVsZXRlOnVzZXJzIGNyZWF0ZTp1c2VycyByZWFkOnVzZXJzX2FwcF9t").Length
($apikey = $assoc1,$assoc2,$assoc3 -join '').Length
# Results
220
220
220
660
$apikey.Count
1
$apikey | clip
如果将其粘贴到记事本中,而未启用“自动换行”功能,则会看到一行内容。
Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5VTTBSRFE1UVROQk9FRTJNREJEUWtGR1JEazFNRGN4TlRReU9FUXpOalZFT0RZeVJEQXpSZyJ9.eyJpc3MiOiJodHRwczovL2lkZW50aXR5LmF1dGgwLWRldi5zcy5hd3MuYmNpZGFoby5jb20vIiwic3ViIjoidHFYQjEwejVUT0ZvZ05rNDAzQmZYZkhrTkJxSVJ0UENAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vaWRlbnRpdHkuYXV0aDAtZGV2LnNzLmF3cy5iY2lkYWhvLmNvbS9hcGkvdjIvIiwiaWF0IjoxNTUzNTI2MDk0LCJleHAiOjE1NTM2MTI0OTQsImF6cCI6InRxWEIxMHo1VE9Gb2dOazQwM0JmWGZIa05CcUlSdFBDIiwic2NvcGUiOiJyZWFkOmNsaWVudF9ncmFudHMgY3JlYXRlOmNsaWVudF9ncmFudHMgZGVsZXRlOmNsaWVudF9ncmFudHMgdXBkYXRlOmNsaWVudF9ncmFudHMgcmVhZDp1c2VycyB1cGRhdGU6dXNlcnMgZGVsZXRlOnVzZXJzIGNyZWF0ZTp1c2VycyByZWFkOnVzZXJzX2FwcF9t
答案 1 :(得分:0)
如果您希望3个字符串在没有分隔符的情况下进行连接 ,即直接连接,请使用-join
的一元形式运算符:
$apikey = -join $assoc1, $assoc2, $assoc3
如果您要输出单个字符串而没有尾随换行符 :
要仅打印到控制台,您可以使用Write-Host -NoNewline $apikey
要保存到文件,请使用Set-Content -NoNewline
或Out-File -NoNewline
(PSv5 +)。