Monday, April 23, 2012

Re: questions about submatch()

On Mon, April 23, 2012 16:00, Ben Fritz wrote:
> On Monday, April 23, 2012 5:19:18 AM UTC-5, rameo wrote:
>> 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?
>
> submatch() has absolutely nothing to do with decimal separators.
> Absolutely nothing. submatch() only gets a string which matched some
> backreference in a regular expression.
>
> Looking at your examples, you're really asking if Vim's floating-point
> calculations can use a comma as a decimal separator (it can't, see :help
> floating-point-format) and a decimal as a thousands separator (I don't
> think I know of ANY program that understands thousands separators, whether
> they be a '.' or a ','; I'm pretty sure Vim cannot recognize them either).

Yes, that's why you have to manually parse the text and react accordingly.
I am doing so with the csv-plugin:
https://github.com/chrisbra/csv.vim/blob/master/ftplugin/csv.vim#L1019

regards,
Christian

--
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

No comments:

Post a Comment