Skip to content

C++ Replace function

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #191358
    Newbie
    Member

    😀

    #include
    #include
    #include 
    
    #191370

    guys whats so deaf about c++ and vb6 what dose c++ do?

    #191369
    function replaceElement()
    
    {
    //The first child of the div is the bold element.
    var oChild=Div1.children(0);
    var sInnerHTML = oChild.innerHTML;
    if (oChild.tagName=="B")
    {
    oNewChild=document.createElement("I");
    Div1.replaceChild(oNewChild, oChild);
    oNewChild.innerHTML=sInnerHTML
    }
    else
    {
    oNewChild=document.createElement("B");
    Div1.replaceChild(oNewChild, oChild);
    oNewChild.innerHTML=sInnerHTML
    }
    }
    Click anywhere in this sentence to toggle this word
    between bold and italic.
    #191368
    Admin
    Administrator

    @VINNIE-GM_01 wrote:

    guys whats so deaf about c++ and vb6 what dose c++ do?

    C++ is a much more powerful coding language…u can do a lot more with it….sky is the limit if u really know wut ur doin….but its a lot harder to learn…..i havnt got past VB lol…. 😆

    #191367
    Ponies
    Member

    ‘sky’ inst all that big you know.

    #191366
    Admin
    Administrator

    but your mom is.

    #191365
    Admin
    Administrator

    lol…..if u keep going up u end up in outer space…lol…. 😆

    #191364
    Ponies
    Member

    witch is VERY big. But isn’t the sky.

    #191363
    Admin
    Administrator

    its an extension of the sky 😀

    #191362
    Dexter
    Member

    The basic has a function called “Replace” which takes 3 strings and does as i described. I looked at the string::replace but none of its forms can take the 3 stings and do the job. If i use a position and size then surely if the replacer is longer than the replace-ee then thats going to overwrite more than i want it too :/ Plus im not sure how to even get the position or length i need either

    #include
    #include
    #include
    #include
    
    using namespace std;
    
    string Replace(string a,string b,string c)
    {
    int pos = a.find(b);
    a.replace(pos, c.length(), c);
    
    return a;
    }
    
    int main()
    
    {
    std::cout << Replace(" Hello World","Hello","goodbye");
    }

    This is my attempt but i am getting
    goodbyeorld

    As its simply overwriting rather than resizing a.

    edit:
    Ah ok fixed it, i needed to supply the length of b. Now i just need to make it parse the whole string 🙂

    Is this the best way of doing this? by (dman (20) )

    #191361
    String
    Member

    Dexter, do not post data from other forums with out posting a link back to the original forum.

    #191360
    Chike
    Member

    This looks like a sophisticated spam bot.
    Only took it 3 minutes from his hello post to this one.
    And of course the n00b has a link in his sig LOL.

    #191359
    waqar_khan
    Member

    Hello guys….!
    Really nice code shared.Great work.I really appreciate your work.I really like this kind of post which tell us much important information. …!

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.