如何更换 .在 Visual Studio 中使用 / 的模式化字符串
我的解决方案中有很多这样的代码:
Localization.Current.GetString("abc.def.gih.klm");
我想将其替换为:
Localization.Current.GetString("/abc/def/gih/klm");
点 (.) 的数量是可变的。
如何在 Visual Studio (2010) 中执行此操作?
编辑:我想替换代码中的字符串(在 VS 2010 编辑器中),而不是在运行应用程序时替换
非常感谢
I have lot of code in our solution like this:
Localization.Current.GetString("abc.def.gih.klm");
I want to replace it with:
Localization.Current.GetString("/abc/def/gih/klm");
the number of dots (.) is variable.
How can I do this in Visual Studio (2010)?
Edit: I want to replace strings in code (in VS 2010 editor), not when I run my application
Thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
误读了您的请求。
如果您按 ctrl+shift h 并将其作为查找字符串
然后将其替换为:
然后在查找选项中勾选使用正则表达式。
这将找到第一个点并替换它。单击“查找下一个”将获得第二个,依此类推。您必须继续进行全部替换,直到全部完成。也许有人可以改进这一点!
如下图
Misread your request.
If you press ctrl+shift h and put this as your find string
Then put this as your replace with:
And then in find options tick use regular expressions.
This will find the first dot and replace it. Clicking find next will get the second one etc. You will have to keep doing a replace all until they are all done. Someone can probably improve that!
As shown below
在“在文件中替换”对话框中尝试使用“使用正则表达式”
查找内容:
如果您想对引号之间允许的字符更加严格,请尝试此操作,
这将只允许引号之间的 ASCII 字符和点。
替换为
它将找到一行中的第一个
"
并将下一个"
之前的最后一个点替换为/
问题是,它只替换每行第一组
""
中点的最后一次出现。因此,您必须多次调用此函数,直到收到消息“未找到文本”,并且要小心
""
之间是否有想要的点。它也将被替换。Try this in the "Replace in Files" Dialogue with "Use Regular expressions"
Find what:
If you want to be a bit more strict on the allowed characters between the quotes then try this
this would allow only ASCII characters and dots between the quotes.
Replace with
It will find the first
"
in a row and replace the last dot before the next"
with/
The problem is, it replaces only the last occurrence of a dot within the first set of
""
in each row. So you would have to call this a few times until you get the message "The text was not found"And be careful if there is a wanted dot between
""
. it will be replaced also.编辑
你不能在Visual Studio中使用它,因为它有它的自己的正则表达式风格,而不是 .NET 正则表达式类中使用的正则表达式,并且我认为您不能用它进行向后查找。
您可以使用此正则表达式:
在查找和替换中,替换为 .
分解:
如果您确定要替换的文本仅有
Localization.Current.GetString
位那么您可以将其包含在正则表达式的lookbehind中:EDIT
you can't use this in visual studio as it has its own flavour of regex, not the one used in the .NET regex classes, and I don't think you can do lookbehind with it.
you can use this regex:
in the find and replace, replacing by .
Breaking it down:
if you are sure that the text that you want to replace only ever has the
Localization.Current.GetString
bit then you could include that in the lookbehind of the regex: