CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Location
    Chennai, India
    Posts
    76

    Inseart a character in between a String

    Hi,

    I have the following string
    a = "12345 , Hae a nice day"

    I need to insert a character "v" in beween "ae" in the string to make it

    a = "12345 , Have a nice day"

    This has to be done for all the occurances of the "ae".
    Is there any function availabe to do this.


    Regards,
    Varadha

  2. #2
    Join Date
    Sep 2002
    Location
    Philippines
    Posts
    197
    try this:
    Code:
    int idx = strInput.Find("ae");
    
    while(idx != -1)
    {
       strInput.Insert(idx + 1, 'v')
       idx = strInput.Find("ae");
    }
    I hope this helps.


    Owen/
    "Hhmn... You are damned if you do; and you are damned if you don't." -- bart simpson

  3. #3
    Join Date
    Sep 2003
    Location
    Chennai, India
    Posts
    76
    here i am using a Char array and i am not using CString.
    is there any C function which i can use to accomplish this..

  4. #4
    Join Date
    May 2004
    Location
    Kuala Lumpur, Malaysia
    Posts
    10
    I don't think so, pal. You got to code it.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637
    You could use a CString and its Replace function, then copy tha resulting string back to you char array.

    It would help to be specific when asking questions. There is an STL string type, an MFC CString, and char arrays, all of which behave differently. It wasn't clear from your post you were using a char array.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured