在 Visual Studio 2010 中计算供选择的非空白字符数

发布于 2024-09-11 13:56:43 字数 142 浏览 2 评论 0原文

有谁知道 Visual Studio 2010 的工具或扩展可以计算文档中当前选择的非空白字符(例如所有字符,但不包括空格、换行符等)?

很高兴有代码高尔夫:)

我有一个命令行工具,但集成工具会非常好。我也更喜欢一些东西来评估当前的选择。

does anyone know of a tool or extension to Visual Studio 2010 to count non-whitespace (e.g. all characters but not spaces, new lines etc.) for current selection in a document?

Nice to have for code golfing :)

I have a command line tool, but an integrated tool would be very nice. Also I would prefer something to evaluate current selection.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

陈独秀 2024-09-18 13:56:43

我最终创建了下面这个粗略的宏,首先在 Visual Studio 中记录一个临时宏,然后将其修改为如下所示:

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module CountNonWhiteSpaceCharacters
    Sub Count()
        Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection()
        Dim text As String = selection.Text

        text = text.Replace(" ", "")
        text = text.Replace(vbCrLf, "")
        text = text.Replace(vbTab, "")

        MsgBox("Count " + text.Length.ToString())
    End Sub    
End Module

如果需要,可以将其绑定到键盘快捷键。否则,在宏资源管理器中双击它即可运行它。

I finally got to creating this crude macro below by first recording a temporary macro in Visual Studio and then modifying it to look like the below:

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module CountNonWhiteSpaceCharacters
    Sub Count()
        Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection()
        Dim text As String = selection.Text

        text = text.Replace(" ", "")
        text = text.Replace(vbCrLf, "")
        text = text.Replace(vbTab, "")

        MsgBox("Count " + text.Length.ToString())
    End Sub    
End Module

This can be bound to a keybord shortcut if desired. Otherwise, double clicking it in Macro Explorer will run it.

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