all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to insert a string every 2 characters
@ 2015-08-22 13:37 Angus Comber
  2015-08-22 14:45 ` tomas
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Angus Comber @ 2015-08-22 13:37 UTC (permalink / raw
  To: Emacs Help

Hi

If I have a string of characters like this:

0102030405

I want to transform into:

01 02 03 04 05

How do I do that?

Angus


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

* Re: How to insert a string every 2 characters
  2015-08-22 13:37 How to insert a string every 2 characters Angus Comber
@ 2015-08-22 14:45 ` tomas
  2015-08-22 14:58   ` Angus Comber
  2015-08-23 21:48   ` Emanuel Berg
  2015-08-23 21:43 ` Emanuel Berg
  2015-08-24 15:12 ` Nicolas Richard
  2 siblings, 2 replies; 11+ messages in thread
From: tomas @ 2015-08-22 14:45 UTC (permalink / raw
  To: Angus Comber; +Cc: Emacs Help

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, Aug 22, 2015 at 02:37:39PM +0100, Angus Comber wrote:
> Hi
> 
> If I have a string of characters like this:
> 
> 0102030405
> 
> I want to transform into:
> 
> 01 02 03 04 05
> 
> How do I do that?

The short answer: query-replace-regexp RET .. RET ..<SPACE>
(substitute the <SPACE> there by a real space, of course).

The long answer: do you have many strings like that? Just
one? How long are they? Do you have to do that very often?

regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlXYixgACgkQBcgs9XrR2kYEFgCfaH9b0KrzKLtzhmnbZdFCcOcT
cwUAn2IoQB2aFnp9EfA1YAdCMri57sED
=npOb
-----END PGP SIGNATURE-----



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

* Re: How to insert a string every 2 characters
  2015-08-22 14:45 ` tomas
@ 2015-08-22 14:58   ` Angus Comber
  2015-08-22 17:03     ` tomas
  2015-08-23 21:48   ` Emanuel Berg
  1 sibling, 1 reply; 11+ messages in thread
From: Angus Comber @ 2015-08-22 14:58 UTC (permalink / raw
  To: tomas; +Cc: Emacs Help

That didn't work quite how I wanted.  It just replaces 2 characters with a
space.  But I I did like this:

c-m-% \(..\)

and replace with \1

with a space after \1 that works.



On 22 August 2015 at 15:45, <tomas@tuxteam.de> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Sat, Aug 22, 2015 at 02:37:39PM +0100, Angus Comber wrote:
> > Hi
> >
> > If I have a string of characters like this:
> >
> > 0102030405
> >
> > I want to transform into:
> >
> > 01 02 03 04 05
> >
> > How do I do that?
>
> The short answer: query-replace-regexp RET .. RET ..<SPACE>
> (substitute the <SPACE> there by a real space, of course).
>
> The long answer: do you have many strings like that? Just
> one? How long are they? Do you have to do that very often?
>
> regards
> - -- tomás
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.12 (GNU/Linux)
>
> iEYEARECAAYFAlXYixgACgkQBcgs9XrR2kYEFgCfaH9b0KrzKLtzhmnbZdFCcOcT
> cwUAn2IoQB2aFnp9EfA1YAdCMri57sED
> =npOb
> -----END PGP SIGNATURE-----
>


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

* Re: How to insert a string every 2 characters
  2015-08-22 14:58   ` Angus Comber
@ 2015-08-22 17:03     ` tomas
  0 siblings, 0 replies; 11+ messages in thread
From: tomas @ 2015-08-22 17:03 UTC (permalink / raw
  To: Angus Comber; +Cc: Emacs Help

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, Aug 22, 2015 at 03:58:05PM +0100, Angus Comber wrote:
> That didn't work quite how I wanted.  It just replaces 2 characters with a
> space.  But I I did like this:
> 
> c-m-% \(..\)
> 
> and replace with \1
> 
> with a space after \1 that works.

Gaah. Excuse my brain fart. I wanted to put \& where I put the right two
dots. Your solution works fine as well, of course.

Sorry. Dunno. Lack of sleep or something.

- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEUEARECAAYFAlXYq00ACgkQBcgs9XrR2kYfHgCZATi61xTwg4HCnQGAYRx6lEIj
Yz0AljzpoU0EMFzoZDSwaeQYiPu3aF0=
=kNUj
-----END PGP SIGNATURE-----



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

* Re: How to insert a string every 2 characters
  2015-08-22 13:37 How to insert a string every 2 characters Angus Comber
  2015-08-22 14:45 ` tomas
@ 2015-08-23 21:43 ` Emanuel Berg
  2015-08-24 15:12 ` Nicolas Richard
  2 siblings, 0 replies; 11+ messages in thread
From: Emanuel Berg @ 2015-08-23 21:43 UTC (permalink / raw
  To: help-gnu-emacs

Angus Comber <anguscomber@gmail.com> writes:

> If I have a string of characters like this:
>
> 0102030405
>
> I want to transform into:
>
> 01 02 03 04 05

(replace-regexp-in-string "\\(..\\)" "\\1 " "0102030405")

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: How to insert a string every 2 characters
  2015-08-22 14:45 ` tomas
  2015-08-22 14:58   ` Angus Comber
@ 2015-08-23 21:48   ` Emanuel Berg
  1 sibling, 0 replies; 11+ messages in thread
From: Emanuel Berg @ 2015-08-23 21:48 UTC (permalink / raw
  To: help-gnu-emacs

<tomas@tuxteam.de> writes:

> The long answer: do you have many strings like that?
> Just one? How long are they? Do you have to do that
> very often?

That isn't an answer but three questions and one
proposed answer to one of the questions.

It is possible I misread the insinuation, but
nevertheless - this is a task that is good to be able
to solve like has been proposed. You don't need to
have many, long strings that often are to be
transformed like this to make it worthwhile. On the
contrary: small things should be solved with advanced
methods before big things should.

You can't put skills in a bag, and expect them to be
there the next time you need it. By then, the bag will
be empty.

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: How to insert a string every 2 characters
  2015-08-22 13:37 How to insert a string every 2 characters Angus Comber
  2015-08-22 14:45 ` tomas
  2015-08-23 21:43 ` Emanuel Berg
@ 2015-08-24 15:12 ` Nicolas Richard
  2015-08-24 20:09   ` Emanuel Berg
  2 siblings, 1 reply; 11+ messages in thread
From: Nicolas Richard @ 2015-08-24 15:12 UTC (permalink / raw
  To: Angus Comber; +Cc: Emacs Help

Angus Comber <anguscomber@gmail.com> writes:

> Hi
>
> If I have a string of characters like this:
>
> 0102030405
>
> I want to transform into:
>
> 01 02 03 04 05
>
> How do I do that?

You could also use a keyboard macro:
<f3> C-f C-f SPC <f4>
then hit <f4> repeatidly (or use C-u 123 <f4> for some value of 123)
until satisfied.

kbd macros tend to be an easy way to automate complex tasks when you
don't have time and don't need to be too smart.

-- 
Nico



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

* Re: How to insert a string every 2 characters
  2015-08-24 15:12 ` Nicolas Richard
@ 2015-08-24 20:09   ` Emanuel Berg
  2015-08-25  9:16     ` Nicolas Richard
  0 siblings, 1 reply; 11+ messages in thread
From: Emanuel Berg @ 2015-08-24 20:09 UTC (permalink / raw
  To: help-gnu-emacs

Nicolas Richard <youngfrog@members.fsf.org> writes:

> You could also use a keyboard macro: <f3> C-f C-f
> SPC <f4> then hit <f4> repeatidly (or use C-u 123
> <f4> for some value of 123) until satisfied.
>
> kbd macros tend to be an easy way to automate
> complex tasks when you don't have time and don't
> need to be too smart.

They sure are!

Act like you are stressed and not too smart, and that
is exactly what you will become.

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: How to insert a string every 2 characters
  2015-08-24 20:09   ` Emanuel Berg
@ 2015-08-25  9:16     ` Nicolas Richard
  2015-08-25 20:39       ` Emanuel Berg
  0 siblings, 1 reply; 11+ messages in thread
From: Nicolas Richard @ 2015-08-25  9:16 UTC (permalink / raw
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:
> Act like you are stressed and not too smart, and that
> is exactly what you will become.

It is too late for me, it seems, because I can't figure out what you're
trying to tell me.

-- 
Nico.



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

* Re: How to insert a string every 2 characters
  2015-08-25  9:16     ` Nicolas Richard
@ 2015-08-25 20:39       ` Emanuel Berg
  2015-08-26 10:55         ` Nicolas Richard
  0 siblings, 1 reply; 11+ messages in thread
From: Emanuel Berg @ 2015-08-25 20:39 UTC (permalink / raw
  To: help-gnu-emacs

Nicolas Richard <youngfrog@members.fsf.org> writes:

>> Act like you are stressed and not too smart, and
>> that is exactly what you will become.
>
> It is too late for me, it seems, because I can't
> figure out what you're trying to tell me.

You said something to the extent that keyboard macros
are quick and not too smart. I assumed you mean
advanced or powerful by "smart", and that those
methods (the smart ones) aren't as quick. Of course,
no one is telling nobody not to use keyboard macros -
only, thinking like that isn't good. If you care about
time, doing technology isn't a good thing to begin
with. Actually it sucks. Anyone who has done physical
work (e.g., digging trenches or whatever) knows that
the perception of time is very disadvantageous when
doing computer work. You can fiddle with some detail
and suddenly two, three hours have gone by! That never
happens when digging, for sure. As for doing the not
too smart thing, doing the smart thing might require
more time the first couple of times doing it, but
eventually it is quicker, tho again if you care about
time, just throw the computer into the wall and be
done with it. The last aspect is what you do is what
you become. Don't look for quick and not too smart
ways to do things, if that isn't what you want to be.
Instead, look for the most powerful way and then to
hell with time. This makes for relaxed and skilled
people. I'm not saying this to you in particular.
But regardless of whatever, that is the way it works.

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: How to insert a string every 2 characters
  2015-08-25 20:39       ` Emanuel Berg
@ 2015-08-26 10:55         ` Nicolas Richard
  0 siblings, 0 replies; 11+ messages in thread
From: Nicolas Richard @ 2015-08-26 10:55 UTC (permalink / raw
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> Nicolas Richard <youngfrog@members.fsf.org> writes:
>
>>> Act like you are stressed and not too smart, and
>>> that is exactly what you will become.
>>
>> It is too late for me, it seems, because I can't
>> figure out what you're trying to tell me.
>
> You said something to the extent that keyboard macros
> are quick and not too smart. I assumed you mean
> advanced or powerful by "smart", and that those
> methods (the smart ones) aren't as quick.

I meant "if you don't need the power of elisp/a reusable function".
Writing a function has its own overhead, because you have to write it,
maybe make it a bit generic, possibly test it, document it (otherwise
future-self will hate you) and put it somewhere you can find it later
(i.e. find a name for it. I've heard that's NP-hard, or something ;)).

>                          Anyone who has done physical
> work (e.g., digging trenches or whatever) knows that
> the perception of time is very disadvantageous when
> doing computer work. You can fiddle with some detail
> and suddenly two, three hours have gone by!

Totally agree. With computers we solve problems that would not exist (or
would be impossible to solve, which is mostly equivalent).

>               The last aspect is what you do is what
> you become. Don't look for quick and not too smart
> ways to do things, if that isn't what you want to be.
> Instead, look for the most powerful way and then to
> hell with time. This makes for relaxed and skilled
> people. I'm not saying this to you in particular.
> But regardless of whatever, that is the way it works.

Obligatory mention of https://xkcd.com/1319/.

-- 
Nico



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

end of thread, other threads:[~2015-08-26 10:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-22 13:37 How to insert a string every 2 characters Angus Comber
2015-08-22 14:45 ` tomas
2015-08-22 14:58   ` Angus Comber
2015-08-22 17:03     ` tomas
2015-08-23 21:48   ` Emanuel Berg
2015-08-23 21:43 ` Emanuel Berg
2015-08-24 15:12 ` Nicolas Richard
2015-08-24 20:09   ` Emanuel Berg
2015-08-25  9:16     ` Nicolas Richard
2015-08-25 20:39       ` Emanuel Berg
2015-08-26 10:55         ` Nicolas Richard

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.