0

How should I parse a icu::UnicodeString string to an integer or float number in ICU4C C++11 ?

Is there a mature API, or I must implement my own number parser?

linrongbin
  • 2,967
  • 6
  • 31
  • 59
  • One simple way is to make your own streambuf class which uses icu::UnicodeString as a buffer (if there isn't such a thing already). Then you have all the parsers available via iostreams in a standard way. – n. m. could be an AI Oct 29 '19 at 08:11
  • @n.m. I've checked the ICU4C document, and I've seen there's something like `icu::number::NumberFormat`, is that available ? – linrongbin Oct 29 '19 at 08:13
  • You can use it if it works for you but I was talking about something different. – n. m. could be an AI Oct 29 '19 at 09:28
  • @n.m. If ICU4C already supported a method, I think use that is better than C++ STL method. – linrongbin Oct 29 '19 at 09:36
  • If you think it's better, then go ahead and use it. I have no idea what you mean by "if" though. You found it in the documentation, what makes you think that it might not be available? – n. m. could be an AI Oct 29 '19 at 09:40
  • @n.m. I've met exceptions when I use `icu::number::NumberFormat`, I don't know how to use it correctly, I need an example. – linrongbin Oct 29 '19 at 10:49
  • If you have a problem with exceptions in `icu::number::NumberFormat`, why not ask a question specifically about that? – n. m. could be an AI Oct 29 '19 at 11:15

0 Answers0