【问题标题】:Find All Fonts with "Arial" in their Name查找名称中带有“Arial”的所有字体
【发布时间】:2016-01-14 01:01:51
【问题描述】:

下面的代码找到字体“Arial”,但我想找到标题中所有 Arial 字体(如“Arial Rounded”、“Arial Unicode”等)。我应该可以使用通配符吧?我一定不知道它去了哪里。有人可以帮我回显所有包含“Arial”的字体吗?

Const FONTS = &H14&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(FONTS)
Set objFolderItem = objFolder.Self

Set colItems = objFolder.Items
For Each objItem In colItems
    If objItem = "Arial" Then
        Wscript.Echo objItem.Name
    End If
Next

【问题讨论】:

    标签: vbscript fonts wsh


    【解决方案1】:

    你几乎已经拥有它了。您只需要检查项目名称是否包含(子)字符串“Arial”:

    For Each objItem in colItems
        If InStr(LCase(objItem.Name), "arial") > 0 Then
            WScript.Echo objItem.Name
        End If
    Next
    

    名称的小写是为了使比较不区分大小写。

    (有点笨拙)InStr 比较的替代方法是使用正则表达式测试项目名称:

    Set re = New RegExp
    re.Pattern = "arial"
    re.IgnoreCase = True
    
    For Each objItem in colItems
        If re.Test(objItem.Name) Then
            WScript.Echo objItem.Name
        End If
    Next
    

    【讨论】:

      猜你喜欢
      • 2016-09-27
      • 2010-11-17
      • 2011-07-31
      • 2016-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      • 2020-10-01
      相关资源
      最近更新 更多