命令行<东西>这将找到一个单词并替换它后面的单词东西>
我需要使用 Visual Studio 预构建命令行操作修改生成的文件。
我可以构建一个批处理文件或一个简单的控制台应用程序来执行此操作,但我想知道我是否在重新发明轮子。
Windows 中是否有一些东西可以让我在文件中搜索单词 namespace 的第一个实例,并将其后面的单词替换为自定义值?
(我正在尝试自动更改生成的文件上的命名空间。)
I need to modify a generated file with a Visual Studio Pre-Build command line action.
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Windows 因此类内置工具而受到困扰。我会选择 GNU sed。
Windows suffers for baked-in tools like this. I'd go for GNU sed.
由于没有人提出解决方案,因此我会这样做。在 AutoHotKey 中,您可以使用如下所示的小脚本:
!0:: ; [Alt]+0(零)执行此操作,您可以将其分配给您喜欢的任何键...
发送,{右}
发送,+^{右}
发送,NEWSTRING{空格}
发送,{F3}
返回
基本思想。您在编辑器中打开该文件(在此示例中为记事本)。搜索第一个单词“命名空间”。然后(安装 AutoHotKey 并添加这个小脚本后),按 [Alt]+0。在 Alt+0 上,脚本将向右跳转一个位置(从突出显示的单词开始),执行 [Shift]+[Ctrl]+[Right] 来选择下一个单词,然后用新的命名空间覆盖突出显示的单词。之后,它发送 [F3] 来查找单词“namespace”的下一个出现位置。再次按 Alt+0 将修改下一个单词...等等...
如果您经常需要这样做,那么您可以创建一个循环,一旦出现“找不到...”消息框,该循环就会停止文件末尾....
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:
!0:: ; [Alt]+0 (zero) to execute this, you could assign this to any key you like...
send, {Right}
Send, +^{Right}
Send, NEWSTRING{Space}
Send, {F3}
Return
Basic idea. You open the file in the editor (in this example Notepad). Search for the first word "namespace". Then (after you installed AutoHotKey and added this little script), you press [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. After that it sends an [F3] to find the next occurance of the word "namespace". Pressing Alt+Zero again will modify the next word...etc...
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....