<div dir="ltr">There are currently no replacements for those functions,<div>the thought was that it was a lot more expensive to traverse the string now so you should only traverse it once,</div><div>or you should at least think about it instead of just replacing the new api.</div><div><br></div><div>I believe 'string:split(File, Ext, trailing)' or why not 'string:replace(File, OldExt, NewExt, trailing)'<br>does what you want in this case, or you could use the 'filename' module for handling filenames.</div><div><br></div><div>But yes the string api could be extended with a function or two.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 6, 2021 at 11:29 PM Olivier Boudeville <<a href="mailto:olivier.boudeville@online.fr">olivier.boudeville@online.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
It must be a silly question, but, since the Latin1 -> Unicode switch in <br>
OTP 20.0, is there a (non-obsolete) way in the string module to look-up <br>
the index of a string into another one, i.e. to find the location of a <br>
given substring?<br>
<br>
rstr/2 is supposed to be replaced with find/3, yet the former returns an <br>
index whereas the latter returns a part of the original string. I could <br>
not find a way to obtain a relevant index with any of the newer string <br>
functions - whereas I would guess it is a fairly common need?<br>
<br>
To give a bit more context, the goal was to prevent the implementation <br>
of [1] from becoming obsolete; string:substr/3 and string:sub_string/3 <br>
are flagged as obsolete and may be replaced by slice/3 (see [2]); yet <br>
what can be done for rstr/2?<br>
<br>
(even if a smart use of some function was found to address the <br>
particular need of this replace_extension/3 function, obtaining indexes <br>
of substrings would still be useful in many cases, isn't it?)<br>
<br>
Thanks in advance for any hint!<br>
<br>
Best regards,<br>
<br>
Olivier.<br>
<br>
<br>
[1] Soon obsolete apparently:<br>
<br>
% Returns a new filename whose extension has been updated.<br>
%<br>
% Ex: replace_extension("/home/jack/rosie.ttf", ".ttf", ".wav") should <br>
return<br>
% "/home/jack/rosie.wav".<br>
%<br>
-spec replace_extension( file_path(), extension(), extension() ) -> <br>
file_path().<br>
replace_extension( FilePath, SourceExtension, TargetExtension ) -><br>
<br>
case string:rstr( FilePath, SourceExtension ) of<br>
<br>
0 -><br>
throw( { extension_not_found, SourceExtension, FilePath } );<br>
<br>
Index -><br>
string:substr( FilePath, 1, Index-1 ) ++ TargetExtension<br>
<br>
end.<br>
<br>
<br>
[2] BTW there is a change in the indexing convention that could be <br>
better advertised in the doc:<br>
<br>
> string:substr("abc",1).<br>
"abc"<br>
<br>
> string:sub_string("abc",1).<br>
"abc"<br>
<br>
> string:slice("abc",1).<br>
"bc"<br>
<br>
> string:slice("abc",0).<br>
"abc"<br>
<br>
-- <br>
Olivier Boudeville<br>
<br>
</blockquote></div>