错误字符串是非数字的,我该如何解决这个问题? [英] error the string is non numeric, how can I solve this problem?

查看:66
本文介绍了错误字符串是非数字的,我该如何解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在水晶报告中有这个问题。我得到这个错误,字符串不是数字。我怎么解决这个问题?

Hi, I have this problem in crystal report. I get this error the string is no numeric. How can I solve this problem?

if {SelOperActivityView.UserActivity} like "Added Card : *" then
    ToNumber (mid ({SelOperActivityView.UserActivity},26,11))
 else if {SelOperActivityView.UserActivity} like "Modified Card*" then
        ToNumber(mid({SelOperActivityView.UserActivity},29,(instr (29,{SelOperActivityView.UserActivity},":")-29)))
 else if {SelOperActivityView.UserActivity} like "Deleted Card :*" then
    ToNumber(mid({SelOperActivityView.UserActivity},28,8));

推荐答案

问题在于你的 ToNumber 函数以及提取数字的方式。



有几种方法可以做到 - 这些样本都在C#但你应该明白这个想法...



如果你能够使用Linq那么
The problem is in your ToNumber function and the way you are extracting the numbers.

There are a few ways of doing it - these samples are in C# but you should get the idea...

If you are able to use Linq then
private string ToNumber1(string parm)
{
    var num = parm.ToCharArray().Where(c => Char.IsDigit(c)).ToArray();
    return new String(num);
}



如果你能使用正则表达式,那么


If you are able to use Regex then

private string ToNumber2(string parm)
{
    //You will need using or imports System.Text.RegularExpressions or the equivalent
    var num = Regex.Match(parm, @"\d+").Value;
    return num;
}



最糟糕的情况是你可以单步执行字符串手动提取数字


Worst case scenario you can step through the string extracting the numbers "manually"

private string ToNumber3(string parm)
{
    //NB as strings are immutable this is not really a good way of doing this
    //If you are able then use the StringBuilder class instead
    string num = string.Empty;
    for (int i = 0; i < parm.Length; i++)
        if (char.IsDigit(parm[i]))
            num += parm[i];
    return num;
}



或者,发布你的 ToNumber函数的代码,我会看看是否可以修复它。



在Crystal语法中,函数看起来像这样(警告 - 未测试也没有语法检查)


Alternatively, post the code for your ToNumber function and I'll see if I can fix it.

In Crystal Syntax the function would look something like this (Warning - not tested nor syntax checked)

//parm is the input string

Local StringVar num  := "";
Local NumberVar i;
For i := 0 To Length(Parm) - 1 Do
(
    Local StringVar parmChar := parm [i];
    Local BooleanVar isDigit := parmChar in "0" to "9";
    If IsDigit Then
    (
        num := num + parmChar;
    )
);
num


这篇关于错误字符串是非数字的,我该如何解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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