Discussion

How to remove spaces in a string

I have a property called last name, and I would like to remove spaces in that name if they appear. For example I would want Del Carmen to be converted to DelCarmen. Is there a way to do this using @substring( )

***Updated by moderator: Marissa to close post***
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Comments

Keep up to date on this post and subscribe to comments

November 4, 2008 - 10:08am

You can use the Rule-Utility-Function @replaceAll(originalString," ","")

-- this replaces all occurrences of the " " with the "".

This is similar to, but not exactly the same as, the Java method String.replaceAll() -- which takes a regex as the first parameter.

November 4, 2008 - 11:21am

Perfect!

Thanks a lot

November 17, 2008 - 1:21pm

I have one more question on this. If the property already has @substring(pyWorkPage.Subscriber.LastName, 0, 17) in the value section of a property set can I add @replaceAll(pyWorkPage.Subscriber.LastName," ","")like the example below?

Properties Name: Message.lastname
Properties Value: @substring(pyWorkPage.Subscriber.LastName, 0, 17) + @replaceAll(pyWorkPage.Subscriber.LastName," ","")

November 17, 2008 - 1:25pm

It will concantenate those two strings, yes. (and if you want a space between them, you'd add a + " " +). Is that what you want?

Jon Garfunkel
Pegasystems

November 17, 2008 - 1:53pm

I want it to do the substring part, and if there is any spaces in the last name eg.(Del Carmen) it will remove the space.

Does it still look correct?

November 19, 2008 - 2:23pm

Eric wrote: I want it to do the substring part, and if there is any spaces in the last name eg.(Del Carmen) it will remove the space.

You are confusing concatenation with composition.
In PRPC function composition is supported as well:

@replaceAll(@substring(pyWorkPage.Subscriber.LastName, 0, 17)," ","")

This is sometimes a bit confusing to read, so you can separate out the functions into separate lines of a Property-Set:

local.seventeenChars = @substring(pyWorkPage.Subscriber.LastName, 0, 17)
local.withOutSpaces = @replaceAll(local.seventeenChars," ","")

November 19, 2008 - 2:31pm

That worked.

Thanks for that solution Jon.

Eric