Skip to Content
author's profile photo Former Member
Former Member

Replace internal spaces in string

I have only recently begun using Crystal Reports 2013. I am having a problem with eliminating errors when creating formulas. I have a database field which is a composite of a fixed length Last Name, First Name and Middle Initial. Because it was fixed length the last name is followed by multiple spaces prior to adding the first name. I would like to remove all the redundant spaces and replace them with a comma and single space. The Replace function, by itself, cannot give me what I need. I have tried multiple times to employ a Do While or a While End While loops to to surround the Replace function, but I continue to receive the same error message of: "The keyword 'do' is missing" Obviously, the keyword is not missing regardless of what case the statement uses. I am at a loss to get the Do While loop to work. I have attempted many different variations and all of them throw this same error. The last formula I attempted looks like this:

Do While {CFTVMA2000.PrvName}.Contains(" ")

Replace({CFTVMA2000.PrvName}," ",", "


I realize that the full syntax may not be correct but I cannot get past the missing 'do' error!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Feb 16, 2016 at 06:57 PM

    Hi Ron,

    What is the fixed length of the last name field?

    Also, do first names and initials also have fixed lengths?

    Could you paste an example string as well?


    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Abhilash Kumar

      THANK YOU! What you sent worked just fine. I was not sure of the original field sizes were but would appear to be around 13-14 characters. Still I have the question of why the Do While loop does not work and always states the 'do' is missing?

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.