[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: reduce repeated backslashes
From: |
Thierry Volpiatto |
Subject: |
Re: reduce repeated backslashes |
Date: |
Mon, 15 Feb 2010 10:12:12 +0100 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/23.1.92 (gnu/linux) |
Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
> Andreas Roehler <andreas.roehler@online.de> writes:
>
>> Hi,
>>
>> don't know how to replace/reduce repeated backslashes
>> from inside a string.
>>
>> Let's assume "abcdef\\\\"
>>
>> Tried
>>
>> (replace-regexp-in-string "\\\\" (number-to-string ?\\) "abcdef\\\\" nil t)
>>
>> which reduces so far, but shows chars as it's numeric value:
>>
>> --> "abcdef9292"
>>
>> Any help? Thanks!
>
> What result do you expect?
>
> `number-to-string' give the string value of a number:
>
> eval:
> ?\\ ==> 92
> (number-to-string ?\\) ==> "92"
>
> `string' will give you the real value of ?char:
> eval:
> (string ?\\) ==> "\\"
>
> May be a better approach is:(if it is what you expect)
>
> (substring "abcdef\\\\" 0 7)
> "abcdef\\"
However:
(replace-regexp-in-string "\\\\\\\\" (string ?\\) "abcdef\\\\" nil t)
==> "abcde\\"
--
Thierry Volpiatto