搜索字符串文字
在寻求本地化的过程中,我需要找到散布在源代码中的所有字符串文字。 我正在寻找一种方法将其编写为修改后源存储库检查的脚本。 (即,在有人检查某些内容后,有一个框设置来检查此统计数据)我可能会使用 NAnt 和 CruiseControl 或其他东西来处理 CVS 的管理(在我的情况下是 StarTeam :( )但是您知道任何可编写脚本的东西吗? (或命令行)实用程序可以准确地循环源代码查找字符串文字?我意识到我可以根据正则表达式进行简单的字符串查找,但想要更划算(也许可以分析字符串或将其分类。 )因为很多时候字符串可能不一定需要翻译有什么想法吗?
In the quest for localization I need to find all the string literals littered amongst our source code. I was looking for a way to script this into a post-modification source repository check. (I.E. after some one checks something in have a box setup to check this stat) I'll probably use NAnt and CruiseControl or something to handle the management of the CVS (Well StarTeam in my case :( ) But do you know of any scriptable (or command line) utility to accurately cycle through source code looking for string literals? I realize I could do simple string look up based on regular expressions but want a little more bang for my buck. (Maybe analyze the string or put it into categories) Because a lot of times the string may not necessarily require translation. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
Visual Studio 2010 及更早版本:
:q
(带引号的字符串)查找结果窗口现在将包含所有文件的报告,包含行号和行本身以及带引号的字符串。
对于 Visual Studio 2012 及更高版本,搜索
((\".+?\")|('.+?'))
(参考,向 @CincauHangus)Visual Studio 2010 and earlier:
:q
(quoted string)Find Results window will now contain a report of all files, with line numbers and the line itself with the quoted string.
For Visual Studio 2012 and later search for
((\".+?\")|('.+?'))
(reference, hat-tip to @CincauHangus)它使用编译的二进制文件而不是源代码,而是使用 Sysinternals 的 Strings 应用程序可能有用。
It uses the compiled binary instead of source, but Sysinternals' Strings app might be useful.
使用正则表达式
对于文字中的特定文本:
"+.*(MYSPECIFICTEXT)+.*"+
对于所有文字
" +.*"+
然后
Use Regular Expressions
For specific text within the literal:
"+.*(MYSPECIFICTEXT)+.*"+
For all literals
"+.*"+
Then
要查找所有
Text="textonly"
实例,请在搜索时使用以下正则表达式:这有助于查找
Text="*"
,但排除已转换为使用的文本资源文件:还可以使用
(>)([az])
查找标签之间的文字,如下所示:To find all
Text="textonly"
instances use the following Regular Expression when searching:This is help for finding
Text="*"
but excluding text that's already been converted to use resource files:Also
(>)([a-z])
can be used to find literals between tags like so:补充一下答案。 要排除注释掉的行和摘要行,请使用以下命令: ^(?!\s{0,}[/]{2,}).+((".+?")|('.+?'))
Complementing the answer. To exclude commented out lines and summary lines, use this : ^(?!\s{0,}[/]{2,}).+((".+?")|('.+?'))
您可能可以使用 CodePlex 上的 C# 解析器。
There's a C# parser on CodePlex that you can probably use.
您好,这是用于搜索文字的正则表达式,我用它来查找要翻译的文本。
它还包括空格和不同的引号
正则表达式:
searchstring: var test='This is a test';
hi this is regex for searching literals, that I use to find a text for translation.
it also includes empty spaces and different quotes
regex:
searchstring: var test='This is a test';