+ Reply to Thread
Results 1 to 12 of 12

Split string to two equal parts

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Split string to two equal parts

    Hello experts
    I have devised code that calculate the length of string and then split it into two equal parts ..

    Please Login or Register  to view this content.
    But I need to skip special characters and numbers and spaces (if found at the split point)

    For example :
    str = "Hi This is for test "", ! 123 How are you?"

    Would be splitted into two parts:
    ---------------------------
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    In this case I would split the string to be like that

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Hope it is clear
    Thanks advanced for any help
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,627

    Re: Split string to two equal parts

    Please Login or Register  to view this content.
    has 15 letters
    Please Login or Register  to view this content.
    has 9 letters

    How is that a half?

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Split string to two equal parts

    Thanks for reply ..
    I have mentioned that it works well for me (the code I attached is working as expected and split the string into two parts)
    But my request is to skip the special characters and spaces and numbers if found at the split point
    In the example : the split point was at the space after the word "test" but I don't need space , nor quotation marks nor numbers nor exclamation mark nor comma ..
    so I don't need equal parts exactly .. but after equal skip special characters

  4. #4
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Split string to two equal parts

    Maybe :

    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Split string to two equal parts

    Mr. Karedog
    Thanks a lot for your wonderful help .. That's really awesome ..
    I don't know anything about VBScript.RegExp .. searched a lot but can't get it ..Is there a beginner source for learning this part?

    Can it be converted to UDF as I would deal with more strings in various subroutines?
    Best Regards

  6. #6
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Split string to two equal parts

    You are welcome, thanks for marking it solved and for the rep. points.

    I am still learning the regex too, it is quite hard for me because we are forced to memorize the syntax for every single rules exists (and I don't like to memorize things )
    Usually I come to these sites for reference :
    http://www.regular-expressions.info/vbscript.html
    http://stackoverflow.com/questions/2...cell-and-loops

    And of course, as usual, google is our best friend, searching using keywords like "vbscript regex tutorial", we will get many.

    Regards

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Split string to two equal parts

    Thank you very much for the links..
    If it was hard for you to learn or memorize it .. so it would be impossible for me to learn even the essentials

    Can the code presented from you be converted to UDF as I would deal with more strings in various subroutines?

  8. #8
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Split string to two equal parts

    Miss the request for UDF :

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Split string to two equal parts

    Thank you very very much for this incredible help
    You are my Champ

  10. #10
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Split string to two equal parts

    Quote Originally Posted by YasserKhalil View Post
    If it was hard for you to learn or memorize it .. so it would be impossible for me to learn even the essentials
    Not really. I remember when I was in elementary school, my friends can do very quick math multiplication, because they remember every shortcut for every base number, for example quadrat number ending with 5 (like 15,25,35), the shortcut is take the first number then multiply this number with (number + 1), then follow by 25, like :
    15x15 = 1 x (1 + 1) followed by 25 --> 225
    25x25 = 2 x (2 + 1) followed by 25 --> 625
    People with good memory, can remember all the shortcuts and make they calculate faster using the shortcuts.

    So if someone keen enough to remember all the rules including the examples that use the rules, I think he will be good at regex.

  11. #11
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Split string to two equal parts

    You are welcome, it's my pleasure.


    Regards

  12. #12
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Split string to two equal parts

    Thank you very much Mr. Karedog
    I had made use of your function in this link
    http://chandoo.org/forum/threads/vba...formula.15957/

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Split a string into 3 parts based on _ sybol
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-31-2016, 06:00 PM
  2. [SOLVED] Split string and apply function on string parts
    By fandreacci in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-25-2015, 12:34 PM
  3. Dividing column in equal parts
    By Dita in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-15-2014, 11:15 AM
  4. [SOLVED] Split a string into parts
    By LeahS in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-01-2013, 09:33 AM
  5. [SOLVED] Searching a string to see if two parts of the string are equal
    By cheal2 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-18-2013, 09:58 AM
  6. Split String into 4 Parts - Max 30 Characters per Cell and Whole Words
    By keithm_007 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-22-2012, 05:56 AM
  7. [SOLVED] Dim String, and divide/split into parts
    By Hallet in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-19-2012, 12:37 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1