Questions from Beginners MQL4 MT4 MetaTrader 4 - page 240

 
Hello all. I can't figure out how to convert string (let's say "hello all") to number double and vice versa from double to string ? Maybe someone has some ready-made code?
 

It was a simple thing to do:

StringToDouble()
DoubleToString()
            
 
Aleksei Stepanenko:

And the puzzle was easy to solve:

The problem is that it's not a number entered as text (e.g. "345.45") that I need to convert to Double, but any text not related to the number itself. When applying e.g.

StringToDouble("Исходный_текст") на выходе будут нули.

It is the same in reverse. You can of course loop through each character of the string using

StringGetChar();

and put their codes into Double, but how to decrypt/receive string from Double ?


So any other options ?

 
Yan Barmin:

The problem is that it's not a number entered as text (e.g. "345.45") that I need to convert to Double, but any text not related to the number itself. When applying e.g.

It is the same in reverse. Any other variants ?

StringToCharArray

 
Yan Barmin:

So are there any other options?

I don't understand the point of this conversion, do you want to get a hash sum? There will be problems with reverse decryption. If the conversion decreases the amount of information, then you are losing it irretrievably.

What number do you want to see here:

StringToDouble("Исходный_текст")
 
Aleksei Stepanenko:

I don't understand the point of this conversion, do you want a hash sum? There will be a problem with reverse decryption. If the conversion decreases the amount of information, then you are losing it irretrievably.

What number do you want to see here?

Probably this one:

void OnStart()
{
   uchar scr[];
   string InputText="Исходный_текст";
   string Res="";
   StringToCharArray(InputText,scr,0,StringLen(InputText));
    for(int i=0; i<ArraySize(scr); i++)
      Res+=scr[i];
    Print(Res); // 20024124523822823725123395242229234241242

}
 

That's funny ;)

You can correspond like that on the forum. History, politics, all the hard stuff, and no one will send you to the ban. Twos, threes, ones...

 
19423224222423523223344322342242342242553224523824023824822425532232228229255322272382262382402322422523224623224424022423623233
 
Now you'll have to write a decoder to read it.
 
Aleksei Stepanenko:
Well, you'll have to write a decoder to read it now.

Well, if it's a string, then you need extra code, but an array directly

   uchar scr[];
   string InputText="Исходный_текст";
   string Res="";
   StringToCharArray(InputText,scr,0,StringLen(InputText));
    for(int i=0; i<ArraySize(scr); i++)
      Res+=scr[i];
  //  Print(Res);
  Print(CharArrayToString(scr));
Reason: