unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* reduce repeated backslashes
@ 2010-02-15  8:40 Andreas Roehler
  2010-02-15  9:03 ` Peter Dyballa
  2010-02-15  9:04 ` Thierry Volpiatto
  0 siblings, 2 replies; 6+ messages in thread
From: Andreas Roehler @ 2010-02-15  8:40 UTC (permalink / raw)
  To: help-gnu-emacs


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!


Andreas

--
https://code.launchpad.net/~a-roehler/python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: reduce repeated backslashes
       [not found] <mailman.1267.1266223114.14305.help-gnu-emacs@gnu.org>
@ 2010-02-15  8:51 ` Teemu Likonen
  2010-02-15 11:55   ` Andreas Röhler
  0 siblings, 1 reply; 6+ messages in thread
From: Teemu Likonen @ 2010-02-15  8:51 UTC (permalink / raw)
  To: help-gnu-emacs

* 2010-02-15 09:40 (+0100), Andreas Roehler wrote:

> don't know how to replace/reduce repeated backslashes from inside a
> string.
>
> Let's assume "abcdef\\\\"

What is the end result you want? I guess:

    (replace-regexp-in-string "\\\\\\\\" "\\" "abcdef\\\\" nil t)
    => "abcdef\\"

There are 8 backslashes in the regexp string because backslash is a meta
character in Lisp strings and also in regexps. 8 backslashes in a regexp
Lisp string means 2 literal backslashes. In the resulting string there
is only one backslash but it is displayed as two "\\" because it's a
printed representation of Lisp string.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: reduce repeated backslashes
  2010-02-15  8:40 Andreas Roehler
@ 2010-02-15  9:03 ` Peter Dyballa
  2010-02-15  9:04 ` Thierry Volpiatto
  1 sibling, 0 replies; 6+ messages in thread
From: Peter Dyballa @ 2010-02-15  9:03 UTC (permalink / raw)
  To: Andreas Roehler; +Cc: help-gnu-emacs


Am 15.02.2010 um 09:40 schrieb Andreas Roehler:

> don't know how to replace/reduce repeated backslashes
> from inside a string.

Replace-string?

--
Mit friedvollen Grüßen

   Pete

A blizzard is when it snows sideways.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: reduce repeated backslashes
  2010-02-15  8:40 Andreas Roehler
  2010-02-15  9:03 ` Peter Dyballa
@ 2010-02-15  9:04 ` Thierry Volpiatto
  2010-02-15  9:12   ` Thierry Volpiatto
  1 sibling, 1 reply; 6+ messages in thread
From: Thierry Volpiatto @ 2010-02-15  9:04 UTC (permalink / raw)
  To: help-gnu-emacs

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


-- 
Thierry Volpiatto





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: reduce repeated backslashes
  2010-02-15  9:04 ` Thierry Volpiatto
@ 2010-02-15  9:12   ` Thierry Volpiatto
  0 siblings, 0 replies; 6+ messages in thread
From: Thierry Volpiatto @ 2010-02-15  9:12 UTC (permalink / raw)
  To: help-gnu-emacs

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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: reduce repeated backslashes
  2010-02-15  8:51 ` reduce repeated backslashes Teemu Likonen
@ 2010-02-15 11:55   ` Andreas Röhler
  0 siblings, 0 replies; 6+ messages in thread
From: Andreas Röhler @ 2010-02-15 11:55 UTC (permalink / raw)
  To: Teemu Likonen; +Cc: Peter Dyballa, help-gnu-emacs, thierry.volpiatto

Teemu Likonen wrote:
> * 2010-02-15 09:40 (+0100), Andreas Roehler wrote:
> 
>> don't know how to replace/reduce repeated backslashes from inside a
>> string.
>>
>> Let's assume "abcdef\\\\"
> 
> What is the end result you want? I guess:
> 
>     (replace-regexp-in-string "\\\\\\\\" "\\" "abcdef\\\\" nil t)
>     => "abcdef\\"
> 
> There are 8 backslashes in the regexp string because backslash is a meta
> character in Lisp strings and also in regexps. 8 backslashes in a regexp
> Lisp string means 2 literal backslashes. In the resulting string there
> is only one backslash but it is displayed as two "\\" because it's a
> printed representation of Lisp string.
> 

Thanks all!

Andreas




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-02-15 11:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1267.1266223114.14305.help-gnu-emacs@gnu.org>
2010-02-15  8:51 ` reduce repeated backslashes Teemu Likonen
2010-02-15 11:55   ` Andreas Röhler
2010-02-15  8:40 Andreas Roehler
2010-02-15  9:03 ` Peter Dyballa
2010-02-15  9:04 ` Thierry Volpiatto
2010-02-15  9:12   ` Thierry Volpiatto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).