Jump to content

Take out a character from a field


rpaterick

Recommended Posts

This will replace it with a space:

 

I thought I was on track.....

I'm not sure on how to do the whole code for the FIELD that has the character.:confused:

 

Thanks

 

if (Field("Full Name").indexOf(String("/")) > -1)
{
  return example.replace("/"," ");
}
else
}
return "";

Link to comment
Share on other sites

I'm not sure on how to do the whole code for the FIELD that has the character.:confused:

 

Thanks

 

if (Field("Full Name").indexOf(String("/")) > -1)
{
  return example.replace("/"," ");
}
else
}
return "";

 

Couple things I noticed first, you're missing an opening brace after the "else" clause. Maybe the JS interpreter is forgiving enough to ignore it? Also, if you aren't getting a match on the slash, you're returning nothing. I don't know if that is your intention.

 

Anyway, you'll need to replace the "example" variable with your field or another variable that you've assigned the field to. Since the replace method won't modify the original string if the search character isn't found, you are safe not performing the "if" check either. In the case above you could shorten it to something like this, which will replace a slash with a space and return that - or will just return the "Full Name" if not found:

return Field("Full Name").replace("/"," ");

 

If you need to replace multiple occurrences of the slash you'll need to use a regular expression match instead.

return Field("Full Name").replace(/\//g," ");

That will replace all forward slashes with a space. The first example will only replace the first slash it finds.

Link to comment
Share on other sites

return Field("Full Name").replace(/\//g," ");

That will replace all forward slashes with a space. The first example will only replace the first slash it finds.

 

Sweet, that worked.

 

How could I add characters to that rule?

Let's say I want to add the character "<" and ">" to the rule.

 

Thanks Tobarstep!

Ryan

Link to comment
Share on other sites

Good deal.

Another way would be to use RegEx again.

return Field("Full Name").replace(/[\<\>\/]/g," ");

Would replace all "<", ">", and "/" with spaces.

 

Yeah, I was trying to piece that together and couldn't figure it out. Since you posted it, I'll use it!

 

Thanks again,:D

Ryan

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...