Message Boards Message Boards

0
|
8129 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Replace hyphen "-" on IntegerName using StringReplace?

Hello,

I have a very simple doubt. I'm unable to use string replace on the output of IntegerName function.

StringReplace[IntegerName[35], "-" -> " "]
"thirty-five"

Its wrong in the above output. But its correct in the below one.

StringReplace["abba-abbaa", "-" -> " "]
"abba abbaa"
POSTED BY: Manjunath Babu
4 Replies

It worked. Thank you.

In:  StringReplace[IntegerName[35, "Words"], 
FromCharacterCode[8208] -> " "]
Out: thirty five
POSTED BY: Manjunath Babu
Posted 7 years ago

If you copy the actual dash and paste that it will work, as Sander points out it isn't actually a hyphen.

POSTED BY: Paul Cleary

As Neil proposed: FullForm is a good way. Alternatively check the character codes:

ToCharacterCode[IntegerName[35]]
ToCharacterCode["-"]   (* a dash *)

{116, 104, 105, 114, 116, 121, 8208, 102, 105, 118, 101}
{45}

a high number generally means it is a 'special' character...

POSTED BY: Sander Huisman

when things like this happen you should look at the fullform and it gives the answer:

IntegerName[35] // FullForm

returns

"thirty\[Hyphen]five"

while

"aaa-gff" // FullForm

returns

"aaa-gff"

You need to replace the [Hyphen] character. Type that in your string instead of the dash.

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract