filename.ino as string variable

Thanks gfvalvo

Very interesting table ! (bookmarked it !)
and wildbill : PERFECT !!! -> 40K thanks !!!
My code looks like this :

String ino = __FILE__;

ino = (ino.substring((ino.indexOf(".")), (ino.lastIndexOf("\\")) + 1));

and the serial monitor displays : SOLARii_MEGA190403b

Can't be better !!!
I'll have a very peaceful sleep tonight thanks to you guys !!! :slight_smile:

Can't be better !!!

It could. You could actually check that the two indexOf() calls returned usable data for the substring call, before you actually try to extract a substring.

While in THIS case, the two indexOf() calls will succeeded, defensive programming is far better than hoping or assuming.

True PaulS,
Apparently you don't want me to sleep tight, right ? :slight_smile: :smiley: ;D

if I "search" in the filename for characters that don't exist like :

ino = (ino.substring((ino.indexOf("Z")), (ino.lastIndexOf("Z")) + 1));

then the serial monitor shows the full path. I could check the lenght of the new ino string, and if it's longer than e.g. 40 (a filename with more than 40 characters is not a filename, but a book ... :wink: ) then I could generate a fault message.
But on the other hand, the original ino string comes from the Arduino IDE ... should I assume that the IDE makes mistakes ?
If there's NO "." and/or no "" in the filename, I think that our IDE will NOT save it ...
But I could change the code in

ino = (ino.substring((ino.indexOf(".ino")), (ino.lastIndexOf("//")) + 1));

then at least I've checked if the IDE saved the sketch with extention ".ino"

For the moment, I have enough space for prog and variables in my sketch, but this is just the start of the second part of my project. I'm using a Mega now, but if possible I want to have it running on an UNO or even a NANO ... so I'm very parsimonious with space ...
With this project I want to monitor my SOLAR panels. I have an "outside" unit (NANO : already working) that will get data from a "panel controller" and transmit these data (and a few others) via wireless or RS485 (not sure yet, have to check and test) to my inside unit. The inside unit will interpret this data and calculates and draws graphs etc.etc. On a MEGA, I'll have more than enough memory, but an UNO/NANO consumes less power...

Wow. No idea where that url tag came from. I've edited it now.

Now, go back up the replies - and see if you can perform this (simple) operation without using String.
It will help you in the future, if you understand how strings (c-strings) are constructed and stored.