String access in FreeFem++

Hello!
Is it possible to access strings in FreeFem++? I am trying to replace specific letters in a string and I don’t know how to do it.

This is the idea of the code (fn is the string):

for(int i = 0; i<fn.length; i++){
		if(fn[i] == '/'){
		fn[i] = '\\';
	}

Thanks!

Yes, use the fn.find("/") to find the location of the first slash string as shown in this example.

Just in case anyone is struggling with the same, this is the way to access the string:

for(int i = 0; i<fn.length; i++){
		if(fn(i:i) == "/"){
		fn(i:i) = "\\";
                }
}

The problem I have now is with the “\”, since I get the error “End of string could not be found”

I guess for anything more complicated, You could use exec. While slow it
will be versatile. For example see below. This uses grep but you could also use sed
or whatever. I left in the erroneous line because it took forever to find the problem lol.

exec("ls| grep edp > foo.txt");
exec("echo  >> foo.txt");
ifstream ifs("foo.txt",binary);
string xxx;
//while (!ifs.eof) { getline(ifs, xxx) ; cout<<" line "<<xxx<endl; cout.flush; }
while (ifs.good()) { getline(ifs, xxx) ; cout<<" line "<<xxx<<endl; cout.flush; }

Another solution:

while (fn.find("/") >= 0) fn(fn.find("/"):fn.find("/")) = "\\";