Skip to content

Instantly share code, notes, and snippets.

@femtotrader
Created January 3, 2015 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save femtotrader/4e55ffa4d67bbf97e0ed to your computer and use it in GitHub Desktop.
Save femtotrader/4e55ffa4d67bbf97e0ed to your computer and use it in GitHub Desktop.
String toolbox for Metatrader
//+------------------------------------------------------------------+
//| string_toolbox.mqh |
//| Copyright © 2014, FemtoTrader |
//| https://sites.google.com/site/femtotrader/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, FemtoTrader"
#property link "https://sites.google.com/site/femtotrader/"
#property version "1.00"
//+------------------------------------------------------------------+
//| Enclose string with simple quote (') |
//+------------------------------------------------------------------+
string quote(string s)
{
return("'" + s + "'");
}
//+------------------------------------------------------------------+
//| Enclose string with doublequote (") |
//+------------------------------------------------------------------+
string doublequote(string s)
{
return("\"" + s + "\"");
}
//+------------------------------------------------------------------+
//| Enclose string with backquote (`) |
//| "backquote" are also called "backtick" |
//+------------------------------------------------------------------+
string backquote(string s)
{
return("`" + s + "`");
}
//+------------------------------------------------------------------+
//| Trim a string left and right |
//+------------------------------------------------------------------+
string StringTrim(string str)
{
str = StringTrimLeft(str);
str = StringTrimRight(str);
return (str);
}
//+------------------------------------------------------------------+
//| Unescape string |
//+------------------------------------------------------------------+
string string_unescape(string s)
{
StringReplace(s,"_ESC1_","'");
StringReplace(s,"_ESC2_","\"");
return(s);
}
//+------------------------------------------------------------------+
//| Escape string |
//+------------------------------------------------------------------+
string string_escape(string s)
{
StringReplace(s,"'","_ESC1_");
StringReplace(s,"\"","_ESC2_");
return(s);
}
//+------------------------------------------------------------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment