如何读取文件中的双引号字符串并保留双引号? [英] How can I read a double quoted string in a file and leave the double quotes intact?

查看:100
本文介绍了如何读取文件中的双引号字符串并保留双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PowerShell脚本新手。 我需要读取包含双引号字符串的文件。 我需要能够阅读双引号字符串并保持双引号不变。 以下是我正在阅读的文件示例:

I'm new to PowerShell scripting.  I need to read a file that contains double quoted strings.  I need to be able to read the double quoted string and keep the double quotes intact.  Here is a sample of the file that I am reading:

END HEADER

BEGIN DSJOB

  标识符"FILE_NAME_SAMPLE"&
   DateModified" 2016-05-17"

END HEADER
BEGIN DSJOB
   Identifier "FILE_NAME_SAMPLE"
   DateModified "2016-05-17"

这似乎应该很简单,但到目前为止我尝试的所有内容都是删除双引号。 我尝试过使用Substring,trim和split失败了。 此外,如果我检查字符串的长度,PowerShell不包括
双引号作为字符串的一部分。 当我阅读它时,我希望能够捕获这个或输出为:

This seems like it should be simple to do but everything that I have tried so far is dropping the double quotes.  I've tried using Substring, trim, and split unsuccessfully.  Also, If I check the length of the string, PowerShell doesn't include the double quotes as part of the string.  When I read it, I'd like to be able to capture this or the output to be this:

" FILE_NAME_SAMPLE"

"FILE_NAME_SAMPLE"

而不是这个没有引号:

FILE_NAME_SAMPLE

FILE_NAME_SAMPLE

我能从你那里得到一点帮助,还是能引导我朝着正确的方向前进?

Can I get a little help from you or can you steer me in the right direction?

谢谢!

AVBARA

推荐答案

阅读脚本中的文件不会删除引号或任何其他字符。 为什么你认为这种情况正在发生?
Reading a file in a script will not remove quotes or any other characters.  Why do you think this is happening?


这篇关于如何读取文件中的双引号字符串并保留双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆