Topic: Replace only second occurrence of an sign
Test with Siren_300_alpha1_build_784_windows.zip, both real text files on disc and with testbed (menu "? > Expression testbed"). Undo works well too.
Q: I want to replace an hyphen/dash/minus "-" by an plus sign "+". But only the second one!
FROM:
SpongeBob, Schwammkopf, S01E17 - Die Schatzsuche - Bus verpasst.ext
SpongeBob, Schwammkopf, S01E18 - Texas - Energisch.ext
SpongeBob, Schwammkopf, S01E19 - Aprilscherze - Ein göttlicher Burger.ext
TO:
SpongeBob, Schwammkopf, S01E17 - Die Schatzsuche + Bus verpasst.ext
SpongeBob, Schwammkopf, S01E18 - Texas + Energisch.ext
SpongeBob, Schwammkopf, S01E19 - Aprilscherze + Ein göttlicher Burger.ext
A: That's looking difficult but can be done easy with Siren
To read what we do now press F1 in Siren
and go to "Expression > Modifiers > String modification : "( )" "
and there a little bit down to
String replacement
The usage is near of the standard "replace" : ( "s1", "s2", s, n, c )
s1 string to replace
s2 replacement string (If it is not specified, the string to replace is deleted)
s starting occurrence (If negative, it is relative to the end of the string)
n number of replacements to do (If negative, all remaining occurrences are treated)
c number indicating if the search is case sensitive : 0 (zero) for no, any other value for yes
To make it easy we use the Siren variable %f which will work on the whole file name incl. the extension.
(To work on the base name only use %b and %e for the extension. But you may need this only to replace all dots but the last.)
So use the
EXPRESSION: %f
and press the Enter-key so the NewName is computed.
You will see the same as in the CurrentName column because %f just is an placeholder for the filename incl. extension.
No modification is done right now.
--
Now we utilize the "String replacement" modifier ( "s1", "s2", s, n, c ) to the %f parameter.
First we start simple and just do the basics: %f("find string", "replacement string")
Or in our case:
EXPRESSION: %f("-", "+")
and press the Enter-key so the NewName is computed.
You will see as NewName something like:
SpongeBob, Schwammkopf, S01E17 + Die Schatzsuche + Bus verpasst.ext
As you may have noticed this has replaced all both hyphens "-" in that name to an plus sign "+"
--
So let use use now one of the advanced parameters ",s ,n ,c" of this expression element :
EXPRESSION: %f("-", "+", 2)
and press the Enter-key so the NewName is computed.
You will see as NewName something like:
SpongeBob, Schwammkopf, S01E17 - Die Schatzsuche + Bus verpasst.ext
where only the second (, 2) hyphen "-" is replaced by an plus sign "+".
Done. Problem solved!
All till now was testing only.
If you are satisfied with this result press the Rename button to do the actual renaming itself.
- - -
More examples?
OK, here we go....
And how would you remove just the first coma?
To get:
SpongeBob Schwammkopf, S01E17 - Die Schatzsuche - Bus verpasst.ext
use EXPRESSION: %f(",","",1,1)
or just %f(",", ,1,1)
which means: find an coma and replace with nothing, or in other words: remove it.
Then the first "1" means start at FIRST occurrence of coma found,
and the second "1" means: work on ONE occurrence only, then stop the work.
You can make an another test run with %f(",", ,2,1)
- - -
And how do both replacements (hyphen and coma) at the same time?
Easy, just use the command separator ";" between both expressions:
%f("-","+",2);%f(",",,1,1)
Note that you can also use more then one "String replacement" modifier on one expression like:
%f("-","+",2)(",",,1,1)
---
Related topics:
Replace the '.' (dots) with ' ' (spaces)
... entferne Punkte aus dem Dateinamen
Press the F1-key while you are in Siren to read more about.
Enjoy Siren, No installation needed, unzip and run. Siren stores it settings into an ini file, not in the Registry.
------------------------------------------------------------------------------------------------------------
Siren is a freeware file renaming program
- portable, highly flexible, powerfully -
If it's looking tricky it's easy to rename with Siren.
http://www.scarabee-software.net/en/siren.html
Now for Windows Win32 and GNU/Linux also:
http://scarabee-software.net/forum/viewtopic.php?id=273