c++csvqtseparatorregional-settings

Detect if the CSV separator is ";" (semicolon) or "," (comma)


Depending on the regional settings, the CSV separator (or the list separator) might be ; instead of ,, which, at least on Windows depends on the Regional Settings.

Is there a cross-platform way to detect what the CSV separator is with Qt?

If no cross-platform way is available, is there a Windows-specific way?


Solution

  • There is QLocale::groupSeparator():

    QChar separator = QLocale().groupSeparator();
    

    Edit:

    But that it not a correct answer. Group separator is a character used in long numbers between number groups, for example: "1,234.56". In that example group separator is comma and decimal separator is period.

    It seems that the QLocale doesn't contain list separator at all. You might try to make a guess according to what decimal separator is used. If decimal separator is . then use , as a CSV separator, if decimal separator is , then use ; as a CSV separator. But I don't know if that covers all languages.