1

I was scraping a page, and I tried to convert some text from page to int, but I got

input string was not in correct format
text is not in English: "۲۳"

But the page codepage is Utf8

At first I tried, int.parse, Convert.ToInt32. No luck, then

byte[] bytes = Encoding.UTF8.GetBytes(eventTime);
var bytDestination = Encoding.Convert(Encoding.UTF8, Encoding.Unicode, bytes);
var resultString = Encoding.Unicode.GetString(bytDestination);

no luck,Same error, (i tried other codepages , like "Default" , "ASCII")

I checked with:

char.IsDigit(eventTimeHourMinue[0]);
char.IsDigit(eventTimeHourMinue[1]);

Noth return true.

How should I Convert this string to int?

Peter B
  • 22,460
  • 5
  • 32
  • 69
Amirreza
  • 575
  • 9
  • 25
  • There is no `Convert`/`Parse` method that I know of that will convert textual numbers in one language to integers. Just like there is no built-in method to convert `one` to `1`. – Ron Beyer Apr 13 '18 at 18:09
  • 2
    If you know what digit `۲` is (and what its nine companions are), write a conversion function to convert that set of digits into regular 0-9 digits that `Int32.Parse()` will understand. – 15ee8f99-57ff-4f92-890c-b56153 Apr 13 '18 at 18:10
  • I'm doing it right know, but i don't like it doing it this was, kinda hope to be some "cleaner way" – Amirreza Apr 13 '18 at 18:13
  • 4
    @Amirreza Just steal the function maccettura linked to, I do it all the time. If he gets hit by a truck, I'll lose my job. [This looks like the best answer there](https://stackoverflow.com/a/30733198/424129), I think. – 15ee8f99-57ff-4f92-890c-b56153 Apr 13 '18 at 18:14
  • @maccettura THAT SHOULD DO IT, thanx – Amirreza Apr 13 '18 at 18:14
  • 1
    I agree with @EdPlunkett about the best answer, although I would make sure you use proper casing since that OP did not – maccettura Apr 13 '18 at 18:16
  • it worked, let's go give some Like to original poster – Amirreza Apr 13 '18 at 18:17

0 Answers0