Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    splitting a string

    Hi,

    I have a string which I want to break up at each capital by putting a space immedately before each one.

    ThisIsThursday should then read like this, This Is Thursday.

    my ( $organisationName1 , $organisationName2, $organisationName3, $organisationName4, $organisationName5) = ($organisationName =~ /(....)/g); # split organisationName after each four characters.

    Then I tried, $organisationName = split(/[A-Z]/); but that A-Z seems not to work

    Can any of you give me an idea. Presently, I am thinking about 'split' then 'join' So any help with splitting on caps would be appreciated.


    Bazz
    Last edited by bazz; 10-27-2005 at 03:05 PM.
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,838
    Thanks
    2
    Thanked 160 Times in 155 Posts
    $organisationName =~ s/([^A-Z])([A-Z])/$1 $2/g;

  • #3
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Thanks FishMonger.

    I'm not sure I can see, readily, how that does it. I don't doubt you; I am just not able to understand it from a read through. I'll play with it and see.

    Bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,838
    Thanks
    2
    Thanked 160 Times in 155 Posts
    The substitution regex looks for (matches) a capital letter preceeded by anything that is not a capital letter and puts the non capital characture into $1 and the capitol char into $2. It then replaces those 2 chars with themselves seperated by a space.

    It can also be written as,

    s/([a-z])([A-Z])/$1 $2/g;

    which alters it to make sure the preceeding char is a lowercase letter.

  • #5
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    I see it now since you wrote it the other way.

    Thanks FishMonger.

    Bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •