Gossamer Forum
Home : General : Perl Programming :

Spliting strings into 2 or 3 at x number...

Quote Reply
Spliting strings into 2 or 3 at x number...
Hi. I am just trying to work out how you can split string at say every 20 characters, and maybe add a <BR> tag there at those intervals.

Anyone got any suggestions? I thought maybe the split() command would do it, but I cant see any way with it Frown

Thanks

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] Spliting strings into 2 or 3 at x number... In reply to
Andy

http://www.perlfaq.com/.../view?view_by_id=115

Cheers

- wil
Quote Reply
Re: [AndyNewby] Spliting strings into 2 or 3 at x number... In reply to
How about:

my @strings = split /.{20}/, $string;

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Spliting strings into 2 or 3 at x number... In reply to
I thought that would have to be:

my @strings = ($string =~ /.{20}/g);

- wil

Last edited by:

Wil: Dec 10, 2001, 2:40 AM
Post deleted by PaulW In reply to
Quote Reply
Re: [PaulW] Spliting strings into 2 or 3 at x number... In reply to
both?

- wil
Quote Reply
Re: [Wil] Spliting strings into 2 or 3 at x number... In reply to
Ah..thanks guys. That should work great Smile

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Post deleted by PaulW In reply to

Last edited by:

PaulW: Dec 10, 2001, 4:01 AM
Quote Reply
Re: [PaulW] Spliting strings into 2 or 3 at x number... In reply to
So you're telling me that the official Perl Documentation is incorrect, yeah?

If you do, maybe you should report it as a bug, Paul?

- wil
Post deleted by PaulW In reply to

Last edited by:

PaulW: Dec 10, 2001, 4:21 AM
Quote Reply
Re: [Wil] Spliting strings into 2 or 3 at x number... In reply to
Glad to see you've found the docs at last at least.
Quote Reply
Re: [PaulW] Spliting strings into 2 or 3 at x number... In reply to
Funny how you hit the delete button on your messages now, eg, Paul?

So you were wrong in assuming that my example was incorrect.

Good day.

- wil
Quote Reply
Re: [Wil] Spliting strings into 2 or 3 at x number... In reply to
Haha, if I hit the delete button just because I was wrong there'd be lots of other deleted posts about.

I never assume anything, the reason I was wrong in this case was due to your use of @strings and $string which I mistyped when testing. I don't have a problem admitting mistakes, it makes me a stronger person.

Last edited by:

PaulW: Dec 10, 2001, 5:06 AM
Quote Reply
Re: [PaulW] Spliting strings into 2 or 3 at x number... In reply to
Really? And I've been going to the gym for all these years. Why didn't you tell me sooner?

The reason I was annoyed was that I posted sample code which you presumed to be incorrect without even looking or testing it properly.

- wil
Quote Reply
Re: [Wil] Spliting strings into 2 or 3 at x number... In reply to
Wil, as I just said it was a typo, I also said I didn't assume, I tested before posting, it was just unfortunate the typo screwed up the result making me think you were wrong.

People do make mistakes you know.


Last edited by:

PaulW: Dec 10, 2001, 5:30 AM