如何从字符串中查找特殊字符

时间:2014-02-25 10:31:43

标签: coldfusion coldfusion-9 coldfusion-10

我需要在字符串中找到特殊字符索引,并将其存储在数组变量中。 下面的代码只显示了第一个特殊字符索引,但我需要知道字符串中所有特殊字符的所有索引。 告诉我该怎么做

<cfoutput>
    <cfset start_var = ArrayNew(1)>

     <cfset g_invalidUsername_Char= "!@##$%^&*()_+=<>?/\,`~}{[];:.|\""0123456789">
    <cfset Firstname="ab!cd!efgh">

    <cfif FindOneOf(g_invalidUsername_Char,(trim(FirstName))) NEQ 0>    
        <cfset QAQC = 0>            
        <cfset AR=" Firstname can only have ' and - .<br>">
        <cfset ARClass ="ARBad">


        <cfset start_var= findoneof(g_invalidUsername_Char,FirstName)>
        #start_var#
        #RemoveChars(FirstName, start_var, 1)#

        </cfif> 
</cfoutput> 

我也试过了Rereplace功能

<cfoutput>
    <cfset start_var = ArrayNew(1)>
     <cfset g_invalidUsername_Char= "! @ ## $ % & * ( ) _ + = <> ? / , ` ~ } { [ ] ; : . |  "" 0 1 2 3 4 5 6 7 8 9 \ ">
    <cfset FirstName="ab!cd""efgh">
    <cfset var_num=0>
    <cfif FindOneOf(g_invalidUsername_Char,(trim(FirstName))) NEQ 0>    
        <cfset QAQC = 0>            
        <cfset AR=" Firstname can only have ' and - .<br>">
        <cfset ARClass ="ARBad">
        <cfloop list="#g_invalidUsername_Char#" index="x" delimiters=" ">
            #x#<br>
            <cfset FirstName = ReReplace(FirstName,"[#x#]", "", "ALL")>
            #FirstName#
        </cfloop>
    </cfif> 
</cfoutput>

但是在rereplace函数中这些“\ ^”两个特殊字符不接受

0 个答案:

没有答案