On Monday, April 23, 2012 8:41:33 AM UTC+2, rameo wrote:
> Hello to all readers,
> 
> I use submatch() to increment/decrement numbers in a text.
> 
> My questions are:
> 1) In my country the "comma" is seen as decimal separator.
>    submatch() doesn't seem to recognize the comma but use the "dot" 
>    as separator.
>    Is there a way to let submatch() know that the decimal separator in the 
>    text is the comma?
> 2) Often the numbers in my text have thousand separators.
>    submatch() doesn't recognize them.
>    %s/1.000.000/\=submatch(0) + 10/g gives as output 11
>    How can I tell submatch that dots are thousand separators?
> 3) In my text I have integers and float values.
>    If I use %s/"a search string"/\=string2float(submatch(0)) [+-]nr/g all 
>    non float values have ".0" after the conversion.
>    If I use %s/"a search string"/\=submatch(0) [+-]nr/g there are no decimals
>    added after the conversion when there are float values.
>    How can I let submatch() know that it has to make a float value when
>    the increment/decrement value or the number self is a float, else it has
>    to see the value as integer?
> 
> Tnx,
> Rameo

John,

I don't know exactly what you think is not clear in my question and  how 
examples can help to clarify.

In text what I use the comma is the decimal separator.
The dot is a thousand separator.
submatch() doesn't recognize the thousand separator and doesn't recognize the 
comma as decimal separator.
submatch() handles different regional settings as the one in my country.
Is there a way to let submatch() my regional settings?
If not .. do I have to convert all xx,xx numbers to xx.xx numbers (substitute 
dot for comma) and all x.xxx.xxx numbers to xxxxxxx numbers (removing the 
thousand separator)?

p.e. 
see these examples:
please put these values in a new buffer:
1.000.000  25,20   10.15  200

These are the the different examples:

%s/1.000.000\|25,20\|10.15\|200/\=submatch(0) + 10/g
output: 11  35   20  210
What I expected: 1.000.010 35,20 (or 35) -- 210

%s/1.000.000\|25,20\|10.15\|200/\=submatch(0) + 1.000/g
output: 2.0  26.0   11.0  201.0
What I expected: 1.001.000 1025 - 1.200

%s/1.000.000\|25,20\|10.15\|200/\=str2float(submatch(0)) + 10,0/g
output: invalid expression
What I expected: 1.000.010,0 35,20 -- 210,0

%s/1.000.000\|25,20\|10.15\|200/\=str2float(submatch(0)) + 1.000/g
output: 2.0  26.0   11.15  201.0
What I expected: 1.001.000 1025,20 -- 1.200





-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to