在经典ASP中拆分字符串 [英] Split string in classic asp

查看:109
本文介绍了在经典ASP中拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用经典的ASP,并且具有如下字符串:

I am working in classic ASP and have a string as below :

A
B
C

A
B
C

现在我想分割字符串,我尝试了vbCrLf,vbNewline,vblf和
,但是它们都不起作用.

Now I want to split the string, I have tried vbCrLf, vbNewline , vblf and
but none of them work.

请为我建议分割字符串的另一种方法.我的修复不好.

Please suggest me an alternative to split the string. I am in a bad fix.

推荐答案

您确定字符串中包含换行符吗?

Are you sure, you have newlines in the string?

首先,您可以输出所有字符代码以找出要分割的字符:

First you can output all character codes to find out, by which character to split:

dim i, c

for i = 1 to len(my_string)
    c = mid(my_string, i, 1)
    Response.Write "CHAR: " & ASC(c) & " = " & c
next

那么您有2个选择:

  1. 如果您可以将一个字符分开(例如char num 10),则可以使用:

  1. If you can split by one character (e.g. char num 10), you can use:

a_result = split(my_string, CHR(10))

  • 您可以使用正则表达式匹配从字符串中获取值.这是很大的开销,但是如果其他所有方法都失败了,请按照以下步骤操作:

  • You can grab values out of your string by using regular expression matching. This is much overhead, but if all else fails, here is how you could do that:

    function findStrings(s_text, s_pattern)
            dim a_out, obj_regex, obj_matches
            dim obj_match, n_index
            set obj_regex = New RegExp
    
            obj_regex.IgnoreCase = true
            obj_regex.Global = true
            obj_regex.MultiLine = true
            obj_regex.Pattern = s_pattern
            set obj_matches = obj_regex.execute(s_text)
            if obj_matches.Count>0 then
                    redim a_out(obj_matches.Count-1)
                    n_index = 0
                    for each obj_match in obj_matches
                            a_out(n_index) = cvStr(obj_match.Value)
                            n_index = n_index + 1
                    next
            end if
            findStrings = a_out
            set obj_regex = Nothing
    end function
    
    a_result = findStrings(my_string, "\w+")
    

  • 这假定您要查找的字符串中没有空格.

    This assumes, that there is no whitespace in the strings you are looking for.

    这篇关于在经典ASP中拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆