Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing words case or abbreviation in sentences
#1
Hi Gintaras, hi all
i need a little help to tune a routine.

In some sentences I want to replace casing or value of certain patterns to keep them always in certain form.
Example, in english, the "i" meaning "me" should always be upper case.

So i did that, which works well:

str ff="the phrase where i want the i in upper case"
ff.replacerx("i" "I" 2|8|32)
out ff gives "the phrase where I want the I in upper case"

So far, so good.

But with certain patterns (i want to rephrase some classical music m4a tags) it fails.

no should become N°
Op. should become Opus

ff.replacerx("no" "N°" 2|8|32)
ff.replacerx("Op." "Opus" 2|8|32)
does not work.

All those patterns are alone, ie previous and following are spaces (bla no bla, bla bala Op. bla bla, my sentence with i is that...)

If you have a solution for the two examples or a better way to achieve my goal...

Thanks
#2
For such simple replacements use findreplace.
Macro Macro2100
Code:
Copy      Help
str ff="the phrase where i want the i in upper case, no, and Op. etc"
str replacements=
;i,I
;no,N°
;Op.,Opus
ICsv x._create; x.FromString(replacements)
int i
for i 0 x.RowCount
,ff.findreplace(x.Cell(i 0) x.Cell(i 1) 2)
out ff
#3
1. Simple is beautiful as usual.

2. Is there a way to put declarations in a macro and load it at boot time to assign it faster?

str replacements.getmacro?

3. I'm not using iCsv at any time so I could not think about that solution, but it opens ideas for the future..
#4
Is loading really too slow? Searching/replacing probably is slower anyway.
#5
In fact, it's both for performance and have clean code: 250 items for substitution if not handy in a single macro.
For speed, I have plenty of RAM on my W8 laptop, so i have a RAMDisk to put files on it....
#6
str replacements.getmacro("replacements")
or
str replacements.getfile("$my qm$\replacements.txt")
#7
You once told me about that but could not put a hand on it.
Thanks, as usual perfect support.
#8
Reopened to adapt it.

Works flawlessly for word replacements, but i'd like to do the same with ponctuation, say replace ":" by " - ".

Show work, but all my attemps, fail, so I suspect a quoting trick to be used. Any idea?

Code should be:

str replacements=
":"," - "
","," "
"?","!"

etc.

The quotes are only to show pairs, does not work in code.
#9
Macro Macro2119
Code:
Copy      Help
str ff="the phrase where i want the i in upper case, no, and Op. etc: more? bb, cc"

;simple words
str replacements=
;i,I
;no,N°
;Op.,Opus
ICsv x._create; x.FromString(replacements)
int i
for i 0 x.RowCount
,ff.findreplace(x.Cell(i 0) x.Cell(i 1) 2)

;regular expressions
replacements=
;" *: *", " - "
;" *, *", " "
;\?, !
x.FromString(replacements)
for i 0 x.RowCount
,ff.replacerx(x.Cell(i 0) x.Cell(i 1))

out ff


Forum Jump:


Users browsing this thread: 1 Guest(s)