VB.NET-在XML字符串中查找字符串

科迪·帕特森

我正在一个项目中,将InfoPath XML文件读入.NET表单。我正在尝试从href获取.xsn版本,以确定应该显示的InfoPath表单版本。由于XML文件中只有1个.xsn字符串,我可以使用它,但是在解析文件名时遇到了麻烦。

http://servername/foldername/forms/fileNameV100.xsn
NoAlias

这是如何解析文件名的示例。您可以使用这些技术来解析版本。其他注释在代码的注释中。

Private Function ParseXsnFileName(ByVal strTarget As String) As String

    Dim strResult As String = String.Empty

    'Get the location of where the .xsn extension starts.
    Dim intExtensionLocation As Integer = strTarget.IndexOf(".xsn")

    If intExtensionLocation >= 0 Then

        'Now we will initiate a loop that iterates back character by character until we find 
        'the forward slash of the URL that preceedes the filename.
        Dim bolStartFound As Boolean = False
        Dim intCursor As Integer = intExtensionLocation

        Do Until intCursor = 0 OrElse bolStartFound

            If strTarget.Substring(intCursor, 1) = "/" Then

                'Setting this to true exist the loop.
                bolStartFound = True

            End If

            intCursor -= 1

        Loop

        If bolStartFound Then

            'We found all of the pieces we need to parse out the filename.

            'Add 2 because of the "intCursor -= 1" and because we don't want the / in the filename.
            Dim intStartLocation As Integer = intCursor + 2

            'Add 4 to StartLocation because we want the extension.
            'Subtract intStartLocation from intExtensionLocation to get the length.
            strResult = strTarget.Substring(intStartLocation, (intExtensionLocation - (intStartLocation + 4)))

        End If

    End If

    Return strResult

End Function

用法示例:

    Dim strParseThis As String = "http://servername/foldername/forms/fileNameV100.xsn"

    Dim strFileName As String = ParseXsnFileName(strParseThis)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

VB.net 在文本中查找特定字符串

来自分类Dev

查找字符串中单词的所有实例,并将其显示在文本框中(vb.net)

来自分类Dev

VB.Net中的字符串与[字符串]

来自分类Dev

VB.Net中的字符串与[字符串]

来自分类Dev

在VB.NET中查找并替换字符串中的字符

来自分类Dev

在vb.net中的字符串之间插入字符

来自分类Dev

VB.NET 字符串中缺少特殊字符

来自分类Dev

vb 如何在字符串中查找字符串并将字符串返回到变量中

来自分类Dev

VB.net字符串提取

来自分类Dev

vb.net字符串操作

来自分类Dev

VB.NET搜索字符串

来自分类Dev

VB.NET在字符串中两个单词之间查找文本

来自分类Dev

VB.NET在字符串中两个单词之间查找文本

来自分类Dev

如何在vb.net的字符串数组中查找和计算重复的数字?

来自分类Dev

vb.net 如何在字符串中查找数字范围

来自分类Dev

从vb.net中的长字符串模式中提取特定的字符串值

来自分类Dev

从VB.NET中的字符串获取子字符串文本

来自分类Dev

在vb.net中获取字符串的子字符串

来自分类Dev

字符串查询中的串联vb.net

来自分类Dev

在vb.net中改组字符串数组

来自分类Dev

vb.net中字符串的多维数组

来自分类Dev

字符串查询中的串联vb.net

来自分类Dev

在vb.net中创建字符串时忽略“”?

来自分类Dev

在vb.net中解析字符串

来自分类Dev

DataTable列到Vb.Net中的字符串数组

来自分类Dev

比较vb.net中的字符串日期

来自分类Dev

如何在vb.net中替换字符串

来自分类Dev

VB.NET 中的连接字符串问题?

来自分类Dev

在 vb.net 中删除部分字符串