String replacement problem.

Posted by fastcodejava on Stack Overflow See other posts from Stack Overflow or by fastcodejava
Published on 2010-04-02T06:33:57Z Indexed on 2010/04/02 6:43 UTC
Read the original article Hit count: 462

Filed under:
|
|

I want to provide some template for a code generator I am developing. A typical pattern for class is :

public ${class_type} ${class_name} extends ${super_class} implements ${interfaces}  {
${class_body}
}

Problem is if super_class is blank or interfaces. I replace extends ${super_class} with empty string. But I get extra spaces. So a class with no super_class and interfaces end up like :

public class Foo    {  //see the extra spaces before {?
${class_body}
}

I know I can replace multiple spaces with single, but is there any better approach?

© Stack Overflow or respective owner

Related posts about java

Related posts about string