试图从字符串中找到值是数字或整数

trying to find the value is numeric or integer from string

对于下面的 url 字符串,我需要找到名为 construction 的参数的值。

<cfset understand = "http://www.example.com/ops.cfm?id=code&construction=148&construction=150&Building=852&Building=665&Building=348&Building=619&Building=625&Building=626&_=1426353166006&action=SUBMIT">

<cfset understand2 = "http://www.example.com/ops.cfm?id=code&construction=AVENT+Construction+Site&construction=Signore+upper+constructions&Building=852&Building=665&Building=348&Building=619&Building=625&Building=626&_=1426353166006&action=SUBMIT">

然后我想检查该值是数字还是字符串。我这样做:

isDefined('understand') and isnumeric(understand)

但它总是returns "NO"。

REGEX 似乎是一个很好的案例,但这不是我的强项。如果您一直在寻找同一项目(建筑)的价值,您可以利用底层 Java 并使用 STRING.split() method. Then use the Coldfusion val() 函数来查看您得到的结果。以下解决方案假定 0 不是有效值。如果是,那么您还有更多工作要做。

<cfscript>
    target=understand;
    //target=understand2;  //uncomment to try the second values
    token="construction=";
    potentialValues = target.split(token); //creates an array of values using the token as a separator
        for (item in potentialValues )
        {
            writeoutput(val(item) & "<br />");  //val will grab the numerical value and ignore everything that follows.  No number will become 0
        }
</cfscript>

试试这个:

constructionIsAt = find(understand, "construction");
characterAfterConstruction = mid(understand, constructionIsAt + 13, 1);
if isNumeric(characterAfterConstruction) {
code for numeric
}
else {
code for non numeric
}