How to get the first letter of the string?



  • hi,
    Is there any standard function(or way) to get the first letter of a given string?
    I tried splitting the string, but that didnt work..
    @ QStringList lineList=line.split(""); //the "line", i read it before from a file
    std::cout<<"the first word of the line :"<<lineList.at(0).toStdString()<<endl;@

    If anybody knows, plz tell me...
    Thank u



  • @
    ((line.constData())[0]).toAscii()
    @


  • Moderators

    Simple answer: line.at(0)

    Complex answer: What do you understand a letter to be?

    With unicode one QChar can be any one of these:

    • something simple as e.g. 'A'.
    • fun stuff like 'LATIN SMALL LIGATURE FFI' (U+FB03) which would most likely be counted as 3 letters by most people
    • only part of one complex glyph (the drawing commonly referred to as "letter"). E.g. you could write 'Ö' (LATIN CAPITAL LETTER O WITH DIAERESIS, U+00D6) as LATIN CAPITAL LETTER O, U+004F followed by COMBINING DIAERESIS, U+0308
    • or even just "half a unicode codepoint" when surrogate pairs are in use, which extend the 16bit unicode space that is addressable directly by UTF-16 used in QString by combining 2 UTF-16 characters.


  • operator[] or at()
    index number is of course zero



  • Thanks a lot for all of u...:)
    i did like this
    @
    std::cout<<"the first word of the line :"<<line.at(0).toAscii()<<endl;
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.