如何更换 .在 Visual Studio 中使用 / 的模式化字符串

发布于 2024-12-11 21:37:04 字数 325 浏览 0 评论 0原文

我的解决方案中有很多这样的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

玩套路吗 2024-12-18 21:37:04

误读了您的请求。

如果您按 ctrl+shift h 并将其作为查找字符串

{Localization\.Current\.GetString\("[A-Za-z\/]+}(\.)

然后将其替换为:

\1/

然后在查找选项中勾选使用正则表达式。

这将找到第一个点并替换它。单击“查找下一个”将获得第二个,依此类推。您必须继续进行全部替换,直到全部完成。也许有人可以改进这一点!

如下图

在此输入图片描述

Misread your request.

If you press ctrl+shift h and put this as your find string

{Localization\.Current\.GetString\("[A-Za-z\/]+}(\.)

Then put this as your replace with:

\1/

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

enter image description here

酸甜透明夹心 2024-12-18 21:37:04

在“在文件中替换”对话框中尝试使用“使用正则表达式”

查找内容:

 {[^"]*"[^"]*}\.

如果您想对引号之间允许的字符更加严格,请尝试此操作,

{[^"]*"[A-Za-z.]*}\.

这将只允许引号之间的 ASCII 字符和点。

替换为

\1/

它将找到一行中的第一个 " 并将下一个 " 之前的最后一个点替换为 /

问题是,它只替换每行第一组 "" 中点的最后一次出现。因此,您必须多次调用此函数,直到收到消息“未找到文本”

,并且要小心 "" 之间是否有想要的点。它也将被替换。

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

{[^"]*"[A-Za-z.]*}\.

this would allow only ASCII characters and dots between the quotes.

Replace with

\1/

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.

淡看悲欢离合 2024-12-18 21:37:04

编辑

你不能在Visual Studio中使用它,因为它有它的自己的正则表达式风格,而不是 .NET 正则表达式类中使用的正则表达式,并且我认为您不能用它进行向后查找。

您可以使用此正则表达式:

(?<=\("[\w.]+)\.

在查找和替换中,替换为 .

分解:

如果您确定要替换的文本仅有Localization.Current.GetString 位那么您可以将其包含在正则表达式的lookbehind中:

(?<=Localization\.Current\.GetString\("[\w.]+)\.

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:

(?<=\("[\w.]+)\.

in the find and replace, replacing by .

Breaking it down:

  • Match a dot (the . at the end)
  • Which is preceeded by (positive look behind) a bracket ( followed by a " and then any number of characters which are letters or a dot (dots don't need to be escaped in a group)

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:

(?<=Localization\.Current\.GetString\("[\w.]+)\.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文