macpee: Of course a period (.) should be numeric since (.) is regarded as the same thing with a period and zero (.0) which is in fact zero (0). Now I tried increasing the number of period (.....) and it is still recognizing it as numeric. We need the code for period (.) so as to eliminate additional period (....) once the first period has been cited in
{
//---
ObjectCreate("SimultaneousReleaseIndex1",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex1",OBJPROP_TEXT,"Four");
ObjectCreate("SimultaneousReleaseIndex2",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex2",OBJPROP_TEXT,"44");
ObjectCreate("SimultaneousReleaseIndex3",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex3",OBJPROP_TEXT,"Forty4");
ObjectCreate("SimultaneousReleaseIndex4",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex4",OBJPROP_TEXT,".1234567890");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex1",OBJPROP_TEXT)))
Print("text1 is numeric");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex2",OBJPROP_TEXT)))
Print("text2 is numeric");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex3",OBJPROP_TEXT)))
Print("text3 is numeric");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex4",OBJPROP_TEXT)))
Print("text4 is numeric");
}
//---
bool IsNumeric(string text)
{
int length=StringLen(text);
for(int i=0;i<length;i++)
{
int char1=StringGetChar(text,i);
if((char1>47 && char1<58) || char1==46)
continue;
else
return(false);
}
return(true);
}
//+------------------------------------------------------------------+
哦,看看我。我早该知道。谢谢你@whroeder1。
另一件事是如何输入负数。代码只需要在输入的开头捕捉到否定符号(-)。
此外,为了完善代码。它需要接受否定符号(-),即使是在数字的中间,如(45-20),并将其视为减法和评估,然后使用代码
整个想法是使 OBT_EDIT 的 OBJPROP_TEXT属性 接受经济日历数据,并将它们视为数字。这就是为什么一个内置的IsNumeric函数相当重要,以避免为它编写不必要的大代码。
当然,句号(.)应该是数字,因为(.)被视为与句号和零(.0)相同的东西,而零(0)实际上是0。现在我试着增加句号的数量(.....),它仍然将其识别为数字。我们需要句号(...)的代码,以便在第一个句号被引用后,消除额外的句号(....)。
另一件事是如何输入负数。代码只需要在输入的开头捕捉到否定符号(-)。
此外,为了完善代码。它需要接受否定符号(-),即使是在数字的中间,如(45-20),并将其视为减法和评估,然后使用代码
整个想法是使 OBT_EDIT 的 OBJPROP_TEXT属性 接受经济日历数据,并将它们视为数字。这就是为什么一个内置的IsNumeric函数相当重要,以避免为其编写不必要的大型代码。
macpee:
Of course a period (.) should be numeric since (.) is regarded as the same thing with a period and zero (.0) which is in fact zero (0). Now I tried increasing the number of period (.....) and it is still recognizing it as numeric. We need the code for period (.) so as to eliminate additional period (....) once the first period has been cited in
另一件事是如何输入负数。代码只需要在输入的开始部分捕获否定符号(-)。
这里有一个回声吗?
是的,这类事情。
你需要注意的是。
________________________________
顺便说一下,我找不到代码的清单(ASCII,我猜)。
来吧,给它一个机会。我知道你一直渴望有机会磨练你的搜索技巧。
________________________________
整个想法是让 OBT_EDIT 的 OBJPROP_TEXT属性 接受经济日历数据,并将它们作为数字处理。这就是为什么一个内置的IsNumeric函数是相当重要的,以避免为它编写不必要的大代码。
虽然我可能误解了你的意图,但如果你想让用户在编辑框中输入日期,然后把它们解释为日期时间(如果你对负数感兴趣,可能就不是了),我不相信这是最好的方法,原因有很多。
这里有回声吗?
________________________________
来吧,给它一个机会。我知道你一直渴望有机会磨练一下你的搜索技巧。
________________________________
虽然我可能误解了你的意图,但如果你想让用户在文本框中输入日期,然后将其解释为日期时间(如果你对负数感兴趣,可能就不是了),我不相信这是最好的方法,原因有很多。
实际上,有关的经济数据并不包括日期--只有 "实际"、"预测"、"以前 "和可能的 "修订 "数据。当然,我们也不打算输入符号,如B(代表十亿),%(代表百分比)等。只有纯实数,没有空格。这个想法是为了计算我所说的 "同时发布指数"。它的目的是结合一组同时发布的经济数据,并将它们视为一个数据。我将把所有的 "实际 "合并为一个 "实际",所有的 "预测 "合并为一个 "预测",等等,以便看到合并的 "实际 "和合并的 "预测 "等之间的关系。
所以。
例如
{
StringReplace(text," ",NULL);
StringReplace(text,",",NULL);
int point_cnt = 0;
for(int i=StringLen(text)-1; i>=0; i--)
{
int this_char = StringGetChar(text,i);
if(this_char == '.')
{
point_cnt++;
if(point_cnt>1) return(false);
if(StringLen(text)<2) return(false);
}
else if(this_char == '+' || this_char == '-')
{
if(i>0) return(false);
}
else if(this_char < '0' || this_char > '9') return(false);
}
return(true);
}
如果它的返回值为真,你可以将该字符串转换为数字。
所以。
例如
{
StringReplace(text," ",NULL);
StringReplace(text,",",NULL);
int point_cnt = 0;
for(int i=StringLen(text)-1; i>=0; i--)
{
int this_char = StringGetChar(text,i);
if(this_char == '.')
{
point_cnt++;
if(point_cnt>1) return(false);
if(StringLen(text)<2) return(false);
}
else if(this_char == '+' || this_char == '-')
{
if(i>0) return(false);
}
else if(this_char < '0' || this_char > '9') return(false);
}
return(true);
}
如果它返回真,你就可以将该字符串转换为数字。