+ Reply to Thread
Results 1 to 10 of 10

replace EACH Nth occurrence a character in a string with another character

  1. #1
    Registered User
    Join Date
    06-22-2016
    Location
    Miami, FL
    MS-Off Ver
    2008 for Mac
    Posts
    5

    replace EACH Nth occurrence a character in a string with another character

    I've seen related posts, but none had an answer I can use on my Mac. I can't seem to use regex find/replace on my mac version. I can't use VBA, only an excel formula.

    Problem: I need to find EACH 2nd occurrence of the string "</li>" and replace it with "</li></ul></div><div class="fourCol"><ul>". The maximum number of insertions is 3, which will create a 4 column grid.

    Ex string:
    <div class="bulletBlock"><div class="fourCol"><ul><li>Chrysler Aspen</li><li> Dodge Durango</li><li> Infiniti FX35</li><li> Infiniti QX70</li><li> Infiniti FX45</li><li> Infiniti FX37</li><li> Jeep Grand Cherokee</li></ul></div></div>

    Desired outcome:
    <div class="bulletBlock"><div class="fourCol"><ul><li>Chrysler Aspen</li><li> Dodge Durango</li></ul></div><div class="fourCol"><ul><li> Infiniti FX35</li><li> Infiniti QX70</li></ul></div><div class="fourCol"><ul><li> Infiniti FX45</li><li> Infiniti FX37</li></ul></div><div class="fourCol"><ul><li> Jeep Grand Cherokee</li></ul></div></div>
    Last edited by mattman7; 06-22-2016 at 09:00 PM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: replace EACH Nth occurrence a character in a string with another character

    Maximum number of occurrences of </li> ???

  3. #3
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: replace EACH Nth occurrence a character in a string with another character

    Withdrawn by FR.
    Dave

  4. #4
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,913

    Re: replace EACH Nth occurrence a character in a string with another character

    Cell B1 = </li></ul></div><div class="fourCol"><ul>

    Maybe

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"</li>",B1,10),"</li>",B1,8),"</li>",B1,6),"</li>",B1,4),"</li>",B1,2)

  5. #5
    Registered User
    Join Date
    06-22-2016
    Location
    Miami, FL
    MS-Off Ver
    2008 for Mac
    Posts
    5
    Quote Originally Posted by JohnTopley View Post
    Maximum number of occurrences of </li> ???
    Maximum number of find/replace points is 3. This will result in a 4 column grid.

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: replace EACH Nth occurrence a character in a string with another character

    mattman7 welcome to the forum.

    I agree with John Topley. We need more information. An uploaded Excel spreadsheet file with enough examples usually helps. That way the data is there, we don't have to re-type / copy / past / format ...... If it doesn't answer our questions at least we will know what the questions are.

  7. #7
    Registered User
    Join Date
    06-22-2016
    Location
    Miami, FL
    MS-Off Ver
    2008 for Mac
    Posts
    5

    Re: replace EACH Nth occurrence a character in a string with another character

    Attached is a sample file. Extra instructions at top of file..
    I hope this helps..
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-22-2016
    Location
    Miami, FL
    MS-Off Ver
    2008 for Mac
    Posts
    5

    Re: replace EACH Nth occurrence a character in a string with another character

    added uploaded file with additional instructions.

  9. #9
    Registered User
    Join Date
    06-22-2016
    Location
    Miami, FL
    MS-Off Ver
    2008 for Mac
    Posts
    5

    Re: replace EACH Nth occurrence a character in a string with another character

    Quote Originally Posted by Phuocam View Post
    Cell B1 = </li></ul></div><div class="fourCol"><ul>

    Maybe

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"</li>",B1,10),"</li>",B1,8),"</li>",B1,6),"</li>",B1,4),"</li>",B1,2)
    This won't work for me as each row has a different number of <li> items. Please see the sample file attached.
    thanks!

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: replace EACH Nth occurrence a character in a string with another character

    In I4 there are 24 "</li> ????

    Based on your first post:

    <div class="bulletBlock"><div class="fourCol"><ul><li>Chrysler Aspen</li><li> Dodge Durango</li><li> Infiniti FX35</li><li> Infiniti QX70</li><li> Infiniti FX45</li><li> Infiniti FX37</li><li> Jeep Grand Cherokee</li></ul></div></div>

    Try on the above:

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A$1,"</li>","***",2),"</li>","***",3),"</li>","***",4),"***",B1)

    I used "***" just make it easier (for me) to see the substitutions

    B1 contains </li> </ul> </div> <div class="fourCol"> <ul>

    You will need many more substitutions for I4 , assuming I understand your requirement correctly.

+ 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 data string into 2 new cells after 4th occurrence of character
    By syncguy in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-30-2015, 10:02 AM
  2. How can I replace a character in a string ?
    By dschmitt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-07-2015, 08:59 AM
  3. [SOLVED] Getting the string that follows the last occurrence of a character
    By michaljireht in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-20-2014, 10:25 AM
  4. [SOLVED] find the character position in a string of the last occurrence of a nominated character
    By jmac1947 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-04-2014, 11:52 PM
  5. Replies: 7
    Last Post: 08-31-2013, 12:30 PM
  6. Cutting off a string at the last occurrence of a character
    By isabelle.r in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-24-2013, 09:42 AM
  7. Replace only one character in string.
    By ali84pk in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-24-2012, 04:39 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