简体   繁体   English

命令行 <Something> 会找到一个单词并替换它之后的单词

[英]Command Line <Something> that will find a word and replace the word after it

I need to modify a generated file with a Visual Studio Pre-Build command line action. 我需要使用Visual Studio Pre-Build命令行操作修改生成的文件。

I could build a batch file or a simple console app to do this, but I am wondering if I am reinventing the wheel. 我可以构建一个批处理文件或一个简单的控制台应用程序来执行此操作,但我想知道我是否正在重新发明轮子。

Is there something baked into windows that would allow me to search a file for the first instance of the word namespace and replace the word after it with a custom value? 是否有一些东西被烘焙到窗口,允许我搜索文件中的第一个单词命名空间实例,并用自定义值替换后面的单词?

(I am trying to automatically change the namespace on a generated file.) (我试图自动更改生成的文件上的命名空间。)

Windows suffers for baked-in tools like this. Windows会受到像这样的烘焙工具的影响。 I'd go for GNU sed . 我会选择GNU sed

Since no-one came up with a solution, here is how I would have done it. 既然没有人想出解决方案,我就是这样做的。 In AutoHotKey you could use a little script like this: 在AutoHotKey中,你可以使用这样的小脚本:

!0:: ; !0 ::; [Alt]+0 (zero) to execute this, you could assign this to any key you like... [Alt] +0(零)执行此操作,您可以将此分配给您喜欢的任何键...

send, {Right} 发送,{右}

Send, +^{Right} 发送,+ ^ {右}

Send, NEWSTRING{Space} 发送,NEWSTRING {Space}

Send, {F3} 发送,{F3}

Return 返回

Basic idea. 基本的想法。 You open the file in the editor (in this example Notepad). 您在编辑器中打开该文件(在此示例中为记事本)。 Search for the first word "namespace". 搜索第一个单词“namespace”。 Then (after you installed AutoHotKey and added this little script), you press [Alt]+0. 然后(在安装AutoHotKey并添加此小脚本后),按[Alt] +0。 On Alt+zero, the script will jump one place to the right(from the highlighted word), them do a [Shift]+[Ctrl]+[Right] to select the next word, then overwrites the highlighted word with your new namespace. 在Alt + 0上,脚本将向右跳一个位置(从突出显示的单词),他们执行[Shift] + [Ctrl] + [Right]选择下一个单词,然后使用新的名称空间覆盖突出显示的单词。 After that it sends an [F3] to find the next occurance of the word "namespace". 之后,它发送[F3]以找到“namespace”一词的下一个出现。 Pressing Alt+Zero again will modify the next word...etc... 再次按Alt + Zero将修改下一个单词......等...

If you need this often, then you could make a loop which will be stopped as soon as the "Can not find...." msgbox is presented at the end of the file.... 如果你经常需要这个,那么你可以创建一个循环,一旦“无法找到....”msgbox出现在文件的末尾就会停止....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM