New to mql4 and really coding in general but I have to start some where. Can anyone help me with this? I have a random string of numbers (different character lengths) that end with .gif. how do I remove just the ".gif" from a string?

Old: 0248240420428420842.gifNew: 0248240420428420842

example 2:

Old: 0824420.gifNew: 0824420

if you could show me the syntax for the exact method that would be even more amazing. thank you

Indeed. Another would be StringSubstr(x, 0, StringLen(x) - 4). But StringReplace will contain an assumption that the extension is always .gif, and never .jpg, .png etc. Use of StringLen contains an assumption that the extension will be .gif, .jpg etc but not .jpeg

The StringFind method wouldn't work if the filenames were capable of being in the form firstpart.secondpart.extension, e.g. EURUSD.0234234234.gif. It would be preferable to use something equivalent to the LastIndexOf() which is available in most programming languages. But MQL4 doesn't have one.

I was assuming it would just remove the .gif and replace it with nothing. Not sure where this "1" came from and what I had done wrong?

The MT4 string functions aren't consistent. StringSubstr() returns the modified string. You are assuming that StringReplace() works the same way, but it doesn't. The first parameter is an in/out string variable, and the return value is the number of replacements made. Your code would need to be:

string fileName2 = fileName; /* Take a copy which is then modified by StringReplace() */
StringReplace(fileName2, ".gif", ""); /* filename2 is modified in place; it is not the function return value */

The MT4 string functions aren't consistent. StringSubstr() returns the modified string. You are assuming that StringReplace() works the same way, but it doesn't. The first parameter is an in/out string variable, and the return value is the number of replacements made. Your code would need to be:

It worked!! Thank you for the details, it will probably help me with a million other things :) thanks!

trader88888: It worked!! Thank you for the details, it will probably help me with a million other things :) thanks!

BTW, your assumption about StringReplace() was incorrect but perfectly reasonable. Every other programming language I can think of works that way.

MT5 isn't consistent: StringSubstr() returns the modified string, but all other manipulation functions such as StringReplace(), StringTrimLeft(), StringToUpper() etc modify their strings in place. When the MQL4 language was expanded in MT4 build 600, it got the MT5 syntax for the new string functions. But StringConcatenate() already existed in MT4, and therefore MT4 and MT5 have different syntax for StringConcatenate(). It's all a mess.