Hi all,
Maybe I'm missing the obvious method to look for blank and/or uninitialized strings. This command works if I explicitly set the var to "", but this does NOT work for uninitialized variables:
string myStringVar; // This variable is uninitialized.
if (myStringVar == "") ...
The following won't compile:
if (myStringVar == NULL) ...
// Error: '==' - different types in comparison
This method seems to work:
if (StringLen(myStringVar) == 0) ... (WORKS!)
Am I missing a more obvious method than this?
Thanks,
Pips4life
P.S. This code demonstrates the problem. The uninitialized
variable does NOT trigger the Print with "1." in the code below.
Maybe I'm missing the obvious method to look for blank and/or uninitialized strings. This command works if I explicitly set the var to "", but this does NOT work for uninitialized variables:
string myStringVar; // This variable is uninitialized.
if (myStringVar == "") ...
The following won't compile:
if (myStringVar == NULL) ...
// Error: '==' - different types in comparison
This method seems to work:
if (StringLen(myStringVar) == 0) ... (WORKS!)
Am I missing a more obvious method than this?
Thanks,
Pips4life
P.S. This code demonstrates the problem. The uninitialized
variable does NOT trigger the Print with "1." in the code below.
Inserted Code
#property copyright "Copyright © 2008, MetaQuotes Software Corp." #property link "[url="http://www.metaquotes.net/"]http://www.metaquotes.net[/url]" #property indicator_chart_window int start() { string Test_No_Initial_Value; string Test_Blank_Value = ""; if (Test_No_Initial_Value == "") Print ("1. Test_No_Initial_Value == \"\" "); if (Test_Blank_Value == "") Print("2. Test_Blank_Value == \"\" "); if (StringLen(Test_No_Initial_Value) == 0) Print ("3. StringLen(Test_No_Initial_Value) == 0 "); if (StringLen(Test_Blank_Value) == 0) Print("4. StringLen(Test_Blank_Value) == 0"); // Next one is illegal syntax: '==' - different types in comparison //if (Test_No_Initial_Value == NULL ) Print ("Test_No_Initial_Value == NULL); return(0); } //+------------------------------------------------------------------+