Problem with StringReplace (% char)

 

If i try to replace a ' # '  or any other char with a ' % ' char this command is not working. It will be replaced by a blank.
Is there any way to make this possible?

string myText =  "TEST#TEST";
StringReplace(myText,"#","%"); 

I need this because i want to send open orders to my webserver by using http request. For example a symbol with name #NOK# is making troubles because in an URL a # symbol needs to be escaped by %23

Thanks in advance

Dokumentation zu MQL5: Stringfunktionen / StringReplace
Dokumentation zu MQL5: Stringfunktionen / StringReplace
  • www.mql5.com
StringReplace - Stringfunktionen - Nachschlagewerk MQL5 - Nachschlagewerk über die Sprache des algothitmischen/automatischen Handels für MetaTrader 5
 
2021.02.13 18:44:37.367 Terminal        MetaTrader 5 x64 build 2783 started for MetaQuotes Software Corp.
2021.02.13 18:44:37.371 Terminal        Windows 10 build 19042, Intel Core i7-9750H  @ 2.60GHz, 25 / 31 Gb memory, 855 / 947 Gb disk, IE 11, UAC, GMT+2
2021.02.13 18:44:37.371 Terminal        C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075


Everything works.

Code:

//+------------------------------------------------------------------+
//|                                                     Script 1.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string myText="TEST#TEST";
   Print("Before ",myText);
   int result=StringReplace(myText,"#","%");
   Print("After ",myText);
  }
//+------------------------------------------------------------------+


Result:

2021.02.14 19:54:42.115 Script 1 (EURUSD,H1)    Before TEST#TEST
2021.02.14 19:54:42.115 Script 1 (EURUSD,H1)    After TEST%TEST
Files:
Script_1.mq5  2 kb
 
#property strict
void OnStart() {
   string s="a#b";
   StringReplace(s,"#", "%23");
   Print(s);
}

2021.02.14 12:50:59.547 testscr USDSGD,Daily: uninit reason 0
2021.02.14 12:50:59.547 testscr USDSGD,Daily: a%23b
2021.02.14 12:50:59.546 testscr USDSGD,Daily: initialized

Your problem is elsewhere.

 

Sorry guys for the confusion! Everything is working well with  StringReplace(myText,"#","%");
The reason why it thought this is not working was the fact that i used  PrintFormat(myText) without any format options instead of Print (myText).

Thanks anyway!

Diego

Dokumentation zu MQL5: Stringfunktionen / StringReplace
Dokumentation zu MQL5: Stringfunktionen / StringReplace
  • www.mql5.com
StringReplace - Stringfunktionen - Nachschlagewerk MQL5 - Nachschlagewerk über die Sprache des algothitmischen/automatischen Handels für MetaTrader 5