How to remove spaces inside a string in


  • Hello All,

    We are supposed to create a Word doc file for our client that is to be used for printing a large list of names and addresses. I am facing the below problem in my Application.


    I am reading the values from the Access Database and showing it in the MS Word Document using windows Application.

    The original name looks like: "Michelle Accuso-Stevens"

    From DataBase side the name looks like this.

    Mich  el  le Acc  uso-Ste  ve  ns [some spaces inside the string] 

    foreach (DataRow myRow in dsContacts.Tables[0].Rows)


    if ("" != myRow["FirstName"].ToString() || "" != myRow["LastName"].ToString().Trim())


    if ("" != myRow["Title"].ToString())


    sw.Write(myRow["Title"].ToString() + " ");


    if ("" != myRow["FirstName"].ToString().Trim())


    sw.Write(myRow["FirstName"].ToString().Trim() + " ");


    if ("" != myRow["LastName"].ToString())







    How Can I replace the spaces inside the string?

    Could you please share your ideas on my query as soon as possible?

    Thanks and Regards


    Thursday, November 23, 2006 7:37 AM


  • Hi

    Looking at your string it seems 2 spaces got added inbetween your string, so ill suggest replace 2 spaces with a empty string.

    xyz.Replace("  ", string.empty);



    Hope this helps

    Thursday, November 23, 2006 8:12 AM

All replies