rpaterick Posted September 1, 2009 Share Posted September 1, 2009 I'd like to take out a character if in the field. If the character "/" is present, is there a way to not print it? Thanks, Ryan Link to comment Share on other sites More sharing options...
tobarstep Posted September 2, 2009 Share Posted September 2, 2009 This will replace it with a space: var example = "I don't want the/to show"; return example.replace("/"," "); This will just get rid of it: var example = "I don't want the/to show"; return example.replace("/",""); Link to comment Share on other sites More sharing options...
rpaterick Posted September 2, 2009 Author Share Posted September 2, 2009 Thanks for showing two different scenarios Tobar! Link to comment Share on other sites More sharing options...
rpaterick Posted September 2, 2009 Author Share Posted September 2, 2009 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. Thanks if (Field("Full Name").indexOf(String("/")) > -1) { return example.replace("/"," "); } else } return ""; Link to comment Share on other sites More sharing options...
tobarstep Posted September 2, 2009 Share Posted September 2, 2009 I'm not sure on how to do the whole code for the FIELD that has the character. 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 More sharing options...
rpaterick Posted September 2, 2009 Author Share Posted September 2, 2009 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 More sharing options...
rpaterick Posted September 2, 2009 Author Share Posted September 2, 2009 Got it worked out. return Field("Full Name").replace("<>"," ").replace("/"," "); Link to comment Share on other sites More sharing options...
tobarstep Posted September 2, 2009 Share Posted September 2, 2009 Got it worked out. return Field("Full Name").replace("<>"," ").replace("/"," "); Good deal. Another way would be to use RegEx again. return Field("Full Name").replace(/[\<\>\/]/g," "); Would replace all "<", ">", and "/" with spaces. Link to comment Share on other sites More sharing options...
rpaterick Posted September 2, 2009 Author Share Posted September 2, 2009 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, Ryan Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.