1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QString Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QString Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QString class provides a Unicode character string. <a href="#details">More...</a></p>
<h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qstring.html#NormalizationForm-enum">NormalizationForm</a></b> { NormalizationForm_D, NormalizationForm_C, NormalizationForm_KD, NormalizationForm_KC }</li><li><div class="fn" />enum <b><a href="qstring.html#SectionFlag-enum">SectionFlag</a></b> { SectionDefault, SectionSkipEmpty, SectionIncludeLeadingSep, SectionIncludeTrailingSep, SectionCaseInsensitiveSeps }</li><li><div class="fn" />class <b><a href="qstring-sectionflags.html">SectionFlags</a></b></li><li><div class="fn" />enum <b><a href="qstring.html#SplitBehavior-enum">SplitBehavior</a></b> { KeepEmptyParts, SkipEmptyParts }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qstring.html#QString">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qstring.html#QString">__init__</a></b> (<i>self</i>, QKeySequence)</li><li><div class="fn" /><b><a href="qstring.html#QString">__init__</a></b> (<i>self</i>, QScriptString)</li><li><div class="fn" /><b><a href="qstring.html#QString-2">__init__</a></b> (<i>self</i>, int <i>size</i>, QChar <i>c</i>)</li><li><div class="fn" /><b><a href="qstring.html#QString-3">__init__</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" /><b><a href="qstring.html#QString-4">__init__</a></b> (<i>self</i>, QByteArray <i>a</i>)</li><li><div class="fn" /><b><a href="qstring.html#QString-5">__init__</a></b> (<i>self</i>, QUuid)</li><li><div class="fn" />QString <b><a href="qstring.html#append">append</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#append-2">append</a></b> (<i>self</i>, QLatin1String <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#append-3">append</a></b> (<i>self</i>, QByteArray <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#arg">arg</a></b> (<i>self</i>, int <i>a</i>, int <i>fieldWidth</i> = 0, int <i>base</i> = 10, QChar <i>fillChar</i> = QLatin1Char(' '))</li><li><div class="fn" />QString <b><a href="qstring.html#arg-2">arg</a></b> (<i>self</i>, float <i>a</i>, int <i>fieldWidth</i> = 0, str <i>format</i> = 'g', int <i>precision</i> = -1, QChar <i>fillChar</i> = QLatin1Char(' '))</li><li><div class="fn" />QString <b><a href="qstring.html#arg-3">arg</a></b> (<i>self</i>, int <i>a</i>, int <i>fieldWidth</i> = 0, int <i>base</i> = 10, QChar <i>fillChar</i> = QLatin1Char(' '))</li><li><div class="fn" />QString <b><a href="qstring.html#arg-4">arg</a></b> (<i>self</i>, int <i>a</i>, int <i>fieldWidth</i> = 0, int <i>base</i> = 10, QChar <i>fillChar</i> = QLatin1Char(' '))</li><li><div class="fn" />QString <b><a href="qstring.html#arg-5">arg</a></b> (<i>self</i>, QString <i>a</i>, int <i>fieldWidth</i> = 0, QChar <i>fillChar</i> = QLatin1Char(' '))</li><li><div class="fn" />QString <b><a href="qstring.html#arg-6">arg</a></b> (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#arg-7">arg</a></b> (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#arg-8">arg</a></b> (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#arg-9">arg</a></b> (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>, QString <i>a5</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#arg-10">arg</a></b> (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>, QString <i>a5</i>, QString <i>a6</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#arg-11">arg</a></b> (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>, QString <i>a5</i>, QString <i>a6</i>, QString <i>a7</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#arg-12">arg</a></b> (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>, QString <i>a5</i>, QString <i>a6</i>, QString <i>a7</i>, QString <i>a8</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#arg-13">arg</a></b> (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>, QString <i>a5</i>, QString <i>a6</i>, QString <i>a7</i>, QString <i>a8</i>, QString <i>a9</i>)</li><li><div class="fn" />QChar <b><a href="qstring.html#at">at</a></b> (<i>self</i>, int <i>i</i>)</li><li><div class="fn" />int <b><a href="qstring.html#capacity">capacity</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qstring.html#chop">chop</a></b> (<i>self</i>, int <i>n</i>)</li><li><div class="fn" /><b><a href="qstring.html#clear">clear</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qstring.html#compare">compare</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />int <b><a href="qstring.html#compare-2">compare</a></b> (<i>self</i>, QString <i>s</i>, Qt.CaseSensitivity <i>cs</i>)</li><li><div class="fn" />int <b><a href="qstring.html#compare-3">compare</a></b> (<i>self</i>, QLatin1String <i>other</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />int <b><a href="qstring.html#compare-4">compare</a></b> (<i>self</i>, QStringRef <i>ref</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />bool <b><a href="qstring.html#contains">contains</a></b> (<i>self</i>, QString <i>str</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />bool <b><a href="qstring.html#contains-2">contains</a></b> (<i>self</i>, QStringRef <i>s</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />bool <b><a href="qstring.html#contains-3">contains</a></b> (<i>self</i>, QRegExp <i>rx</i>)</li><li><div class="fn" />int <b><a href="qstring.html#count">count</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qstring.html#count-2">count</a></b> (<i>self</i>, QString <i>str</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />int <b><a href="qstring.html#count-3">count</a></b> (<i>self</i>, QStringRef <i>str</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />int <b><a href="qstring.html#count-4">count</a></b> (<i>self</i>, QRegExp)</li><li><div class="fn" />bool <b><a href="qstring.html#endsWith">endsWith</a></b> (<i>self</i>, QString <i>s</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />bool <b><a href="qstring.html#endsWith-2">endsWith</a></b> (<i>self</i>, QStringRef <i>s</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />bool <b><a href="qstring.html#endsWith-3">endsWith</a></b> (<i>self</i>, QLatin1String <i>s</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />QString <b><a href="qstring.html#fill">fill</a></b> (<i>self</i>, QChar <i>ch</i>, int <i>size</i> = -1)</li><li><div class="fn" />int <b><a href="qstring.html#indexOf">indexOf</a></b> (<i>self</i>, QString <i>str</i>, int <i>from</i> = 0, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />int <b><a href="qstring.html#indexOf-2">indexOf</a></b> (<i>self</i>, QStringRef <i>str</i>, int <i>from</i> = 0, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />int <b><a href="qstring.html#indexOf-3">indexOf</a></b> (<i>self</i>, QLatin1String <i>str</i>, int <i>from</i> = 0, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />int <b><a href="qstring.html#indexOf-4">indexOf</a></b> (<i>self</i>, QRegExp <i>rx</i>, int <i>from</i> = 0)</li><li><div class="fn" />QString <b><a href="qstring.html#insert">insert</a></b> (<i>self</i>, int <i>i</i>, QString <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#insert-2">insert</a></b> (<i>self</i>, int <i>i</i>, QLatin1String <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#isEmpty">isEmpty</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#isNull">isNull</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#isRightToLeft">isRightToLeft</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#isSimpleText">isSimpleText</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qstring.html#lastIndexOf">lastIndexOf</a></b> (<i>self</i>, QString <i>str</i>, int <i>from</i> = -1, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />int <b><a href="qstring.html#lastIndexOf-2">lastIndexOf</a></b> (<i>self</i>, QStringRef <i>str</i>, int <i>from</i> = -1, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />int <b><a href="qstring.html#lastIndexOf-3">lastIndexOf</a></b> (<i>self</i>, QLatin1String <i>str</i>, int <i>from</i> = -1, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />int <b><a href="qstring.html#lastIndexOf-4">lastIndexOf</a></b> (<i>self</i>, QRegExp <i>rx</i>, int <i>from</i> = -1)</li><li><div class="fn" />QString <b><a href="qstring.html#left">left</a></b> (<i>self</i>, int <i>len</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#leftJustified">leftJustified</a></b> (<i>self</i>, int <i>width</i>, QChar <i>fillChar</i> = QLatin1Char(' '), bool <i>truncate</i> = False)</li><li><div class="fn" />int <b><a href="qstring.html#length">length</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qstring.html#localeAwareCompare">localeAwareCompare</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />int <b><a href="qstring.html#localeAwareCompare-2">localeAwareCompare</a></b> (<i>self</i>, QStringRef <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#mid">mid</a></b> (<i>self</i>, int <i>position</i>, int <i>n</i> = -1)</li><li><div class="fn" />QString <b><a href="qstring.html#normalized">normalized</a></b> (<i>self</i>, NormalizationForm <i>mode</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#normalized-2">normalized</a></b> (<i>self</i>, NormalizationForm <i>mode</i>, QChar.UnicodeVersion <i>version</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#prepend">prepend</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#prepend-2">prepend</a></b> (<i>self</i>, QLatin1String <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#prepend-3">prepend</a></b> (<i>self</i>, QByteArray <i>s</i>)</li><li><div class="fn" /><b><a href="qstring.html#push_back">push_back</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" /><b><a href="qstring.html#push_front">push_front</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#remove">remove</a></b> (<i>self</i>, int <i>i</i>, int <i>len</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#remove-2">remove</a></b> (<i>self</i>, QString <i>str</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />QString <b><a href="qstring.html#remove-3">remove</a></b> (<i>self</i>, QRegExp <i>rx</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#repeated">repeated</a></b> (<i>self</i>, int <i>times</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#replace">replace</a></b> (<i>self</i>, int <i>i</i>, int <i>len</i>, QString <i>after</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#replace-2">replace</a></b> (<i>self</i>, QString <i>before</i>, QString <i>after</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />QString <b><a href="qstring.html#replace-3">replace</a></b> (<i>self</i>, QRegExp <i>rx</i>, QString <i>after</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#replace-4">replace</a></b> (<i>self</i>, QLatin1String <i>before</i>, QLatin1String <i>after</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />QString <b><a href="qstring.html#replace-5">replace</a></b> (<i>self</i>, QLatin1String <i>before</i>, QString <i>after</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />QString <b><a href="qstring.html#replace-6">replace</a></b> (<i>self</i>, QString <i>before</i>, QLatin1String <i>after</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" /><b><a href="qstring.html#reserve">reserve</a></b> (<i>self</i>, int <i>asize</i>)</li><li><div class="fn" /><b><a href="qstring.html#resize">resize</a></b> (<i>self</i>, int <i>size</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#right">right</a></b> (<i>self</i>, int <i>len</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#rightJustified">rightJustified</a></b> (<i>self</i>, int <i>width</i>, QChar <i>fillChar</i> = QLatin1Char(' '), bool <i>truncate</i> = False)</li><li><div class="fn" />QString <b><a href="qstring.html#section">section</a></b> (<i>self</i>, QString <i>sep</i>, int <i>start</i>, int <i>end</i> = -1, SectionFlags <i>flags</i> = QString.SectionDefault)</li><li><div class="fn" />QString <b><a href="qstring.html#section-2">section</a></b> (<i>self</i>, QRegExp <i>reg</i>, int <i>start</i>, int <i>end</i> = -1, SectionFlags <i>flags</i> = QString.SectionDefault)</li><li><div class="fn" />QString <b><a href="qstring.html#setNum">setNum</a></b> (<i>self</i>, int <i>n</i>, int <i>base</i> = 10)</li><li><div class="fn" />QString <b><a href="qstring.html#setNum-2">setNum</a></b> (<i>self</i>, float <i>n</i>, str <i>format</i> = 'g', int <i>precision</i> = 6)</li><li><div class="fn" />QString <b><a href="qstring.html#setNum-3">setNum</a></b> (<i>self</i>, int <i>n</i>, int <i>base</i> = 10)</li><li><div class="fn" />QString <b><a href="qstring.html#setNum-4">setNum</a></b> (<i>self</i>, int <i>n</i>, int <i>base</i> = 10)</li><li><div class="fn" />QString <b><a href="qstring.html#simplified">simplified</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qstring.html#size">size</a></b> (<i>self</i>)</li><li><div class="fn" />QStringList <b><a href="qstring.html#split">split</a></b> (<i>self</i>, QString <i>sep</i>, SplitBehavior <i>behavior</i> = QString.KeepEmptyParts, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />QStringList <b><a href="qstring.html#split-2">split</a></b> (<i>self</i>, QRegExp <i>sep</i>, SplitBehavior <i>behavior</i> = QString.KeepEmptyParts)</li><li><div class="fn" /><b><a href="qstring.html#squeeze">squeeze</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#startsWith">startsWith</a></b> (<i>self</i>, QString <i>s</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />bool <b><a href="qstring.html#startsWith-2">startsWith</a></b> (<i>self</i>, QStringRef <i>s</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />bool <b><a href="qstring.html#startsWith-3">startsWith</a></b> (<i>self</i>, QLatin1String <i>s</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" /><b><a href="qstring.html#swap">swap</a></b> (<i>self</i>, QString <i>other</i>)</li><li><div class="fn" />QByteArray <b><a href="qstring.html#toAscii">toAscii</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#toCaseFolded">toCaseFolded</a></b> (<i>self</i>)</li><li><div class="fn" />(float, bool <i>ok</i>) <b><a href="qstring.html#toDouble">toDouble</a></b> (<i>self</i>)</li><li><div class="fn" />(float, bool <i>ok</i>) <b><a href="qstring.html#toFloat">toFloat</a></b> (<i>self</i>)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qstring.html#toInt">toInt</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />QByteArray <b><a href="qstring.html#toLatin1">toLatin1</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray <b><a href="qstring.html#toLocal8Bit">toLocal8Bit</a></b> (<i>self</i>)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qstring.html#toLong">toLong</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qstring.html#toLongLong">toLongLong</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />QString <b><a href="qstring.html#toLower">toLower</a></b> (<i>self</i>)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qstring.html#toShort">toShort</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qstring.html#toUInt">toUInt</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qstring.html#toULong">toULong</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qstring.html#toULongLong">toULongLong</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />QString <b><a href="qstring.html#toUpper">toUpper</a></b> (<i>self</i>)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qstring.html#toUShort">toUShort</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />QByteArray <b><a href="qstring.html#toUtf8">toUtf8</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#trimmed">trimmed</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qstring.html#truncate">truncate</a></b> (<i>self</i>, int <i>pos</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />int <b><a href="qstring.html#compare-5">compare</a></b> (QString <i>s1</i>, QString <i>s2</i>)</li><li><div class="fn" />int <b><a href="qstring.html#compare-6">compare</a></b> (QString <i>s1</i>, QString <i>s2</i>, Qt.CaseSensitivity <i>cs</i>)</li><li><div class="fn" />int <b><a href="qstring.html#compare-7">compare</a></b> (QString <i>s1</i>, QLatin1String <i>s2</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />int <b><a href="qstring.html#compare-8">compare</a></b> (QLatin1String <i>s1</i>, QString <i>s2</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />int <b><a href="qstring.html#compare-9">compare</a></b> (QString <i>s1</i>, QStringRef <i>s2</i>, Qt.CaseSensitivity <i>cs</i> = Qt.CaseSensitive)</li><li><div class="fn" />QString <b><a href="qstring.html#fromAscii">fromAscii</a></b> (str <i>str</i>, int <i>size</i> = -1)</li><li><div class="fn" />QString <b><a href="qstring.html#fromLatin1">fromLatin1</a></b> (str <i>str</i>, int <i>size</i> = -1)</li><li><div class="fn" />QString <b><a href="qstring.html#fromLocal8Bit">fromLocal8Bit</a></b> (str <i>str</i>, int <i>size</i> = -1)</li><li><div class="fn" />QString <b><a href="qstring.html#fromUtf8">fromUtf8</a></b> (str <i>str</i>, int <i>size</i> = -1)</li><li><div class="fn" />int <b><a href="qstring.html#localeAwareCompare-3">localeAwareCompare</a></b> (QString <i>s1</i>, QString <i>s2</i>)</li><li><div class="fn" />int <b><a href="qstring.html#localeAwareCompare-4">localeAwareCompare</a></b> (QString <i>s1</i>, QStringRef <i>s2</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#number">number</a></b> (int <i>n</i>, int <i>base</i> = 10)</li><li><div class="fn" />QString <b><a href="qstring.html#number-2">number</a></b> (float <i>n</i>, str <i>format</i> = 'g', int <i>precision</i> = 6)</li><li><div class="fn" />QString <b><a href="qstring.html#number-3">number</a></b> (int <i>n</i>, int <i>base</i> = 10)</li><li><div class="fn" />QString <b><a href="qstring.html#number-4">number</a></b> (int <i>n</i>, int <i>base</i> = 10)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" />QString <b><a href="qstring.html#__add__">__add__</a></b> (<i>self</i>, QString <i>s2</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#__add__-2">__add__</a></b> (<i>self</i>, QByteArray <i>ba</i>)</li><li><div class="fn" />int <b><a href="qstring.html#__contains__">__contains__</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__eq__">__eq__</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__eq__-2">__eq__</a></b> (<i>self</i>, QLatin1String <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__eq__-3">__eq__</a></b> (<i>self</i>, QByteArray <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__eq__-4">__eq__</a></b> (<i>self</i>, QStringRef <i>s2</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__ge__">__ge__</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__ge__-2">__ge__</a></b> (<i>self</i>, QLatin1String <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__ge__-3">__ge__</a></b> (<i>self</i>, QByteArray <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#__getitem__">__getitem__</a></b> (<i>self</i>, int <i>i</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#__getitem__-2">__getitem__</a></b> (<i>self</i>, slice <i>slice</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__gt__">__gt__</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__gt__-2">__gt__</a></b> (<i>self</i>, QLatin1String <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__gt__-3">__gt__</a></b> (<i>self</i>, QByteArray <i>s</i>)</li><li><div class="fn" />int <b><a href="qstring.html#__hash__">__hash__</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#__iadd__">__iadd__</a></b> (<i>self</i>, QChar.SpecialCharacter <i>c</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#__iadd__-2">__iadd__</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#__iadd__-3">__iadd__</a></b> (<i>self</i>, QLatin1String <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#__iadd__-4">__iadd__</a></b> (<i>self</i>, QByteArray <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#__imul__">__imul__</a></b> (<i>self</i>, int <i>m</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__le__">__le__</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__le__-2">__le__</a></b> (<i>self</i>, QLatin1String <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__le__-3">__le__</a></b> (<i>self</i>, QByteArray <i>s</i>)</li><li><div class="fn" /> <b><a href="qstring.html#__len__">__len__</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__lt__">__lt__</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__lt__-2">__lt__</a></b> (<i>self</i>, QLatin1String <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__lt__-3">__lt__</a></b> (<i>self</i>, QByteArray <i>s</i>)</li><li><div class="fn" />QString <b><a href="qstring.html#__mul__">__mul__</a></b> (<i>self</i>, int <i>m</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__ne__">__ne__</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__ne__-2">__ne__</a></b> (<i>self</i>, QLatin1String <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__ne__-3">__ne__</a></b> (<i>self</i>, QByteArray <i>s</i>)</li><li><div class="fn" />bool <b><a href="qstring.html#__ne__-4">__ne__</a></b> (<i>self</i>, QStringRef <i>s2</i>)</li><li><div class="fn" />str <b><a href="qstring.html#__repr__">__repr__</a></b> (<i>self</i>)</li><li><div class="fn" />str <b><a href="qstring.html#__str__">__str__</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>This class can be pickled.</p><p>A Python string or unicode object, a
<a href="qlatin1string.html">QLatin1String</a> or a
<a href="qchar.html">QChar</a>
may be used whenever a
<a href="qstring.html">QString</a>
is expected.</p>
<p>The QString class provides a Unicode character string.</p>
<p>QString stores a string of 16-bit <a href="qchar.html">QChar</a>s, where each <a href="qchar.html">QChar</a>
corresponds one Unicode 4.0 character. (Unicode characters with
code values above 65535 are stored using surrogate pairs, i.e., two
consecutive <a href="qchar.html">QChar</a>s.)</p>
<p><a href="unicode.html#unicode">Unicode</a> is an international
standard that supports most of the writing systems in use today. It
is a superset of US-ASCII (ANSI X3.4-1986) and Latin-1 (ISO
8859-1), and all the US-ASCII/Latin-1 characters are available at
the same code positions.</p>
<p>Behind the scenes, QString uses <a href="implicit-sharing.html">implicit sharing</a> (copy-on-write) to
reduce memory usage and to avoid the needless copying of data. This
also helps reduce the inherent overhead of storing 16-bit
characters instead of 8-bit characters.</p>
<p>In addition to QString, Qt also provides the <a href="qbytearray.html">QByteArray</a> class to store raw bytes and
traditional 8-bit '\0'-terminated strings. For most purposes,
QString is the class you want to use. It is used throughout the Qt
API, and the Unicode support ensures that your applications will be
easy to translate if you want to expand your application's market
at some point. The two main cases where <a href="qbytearray.html">QByteArray</a> is appropriate are when you need
to store raw binary data, and when memory conservation is critical
(e.g., with <a href="qt-embedded-linux.html">Qt for Embedded
Linux</a>).</p>
<a id="initializing-a-string" name="initializing-a-string" />
<h3>Initializing a String</h3>
<p>One way to initialize a QString is simply to pass a <tt>const
char *</tt> to its constructor. For example, the following code
creates a QString of size 5 containing the data "Hello":</p>
<pre class="cpp">
<span class="type">QString</span> str <span class="operator">=</span> <span class="string">"Hello"</span>;
</pre>
<p>QString converts the <tt>const char *</tt> data into Unicode
using the <a href="qstring.html#fromAscii">fromAscii</a>()
function. By default, <a href="qstring.html#fromAscii">fromAscii</a>() treats character above 128
as Latin-1 characters, but this can be changed by calling <a href="qtextcodec.html#setCodecForCStrings">QTextCodec.setCodecForCStrings</a>().</p>
<p>In all of the QString functions that take <tt>const char *</tt>
parameters, the <tt>const char *</tt> is interpreted as a classic
C-style '\0'-terminated string. It is legal for the <tt>const char
*</tt> parameter to be 0.</p>
<p>You can also provide string data as an array of <a href="qchar.html">QChar</a>s:</p>
<pre class="cpp">
<span class="keyword">static</span> <span class="keyword">const</span> <span class="type"><a href="qchar.html">QChar</a></span> data<span class="operator">[</span><span class="number">4</span><span class="operator">]</span> <span class="operator">=</span> { <span class="number">0x0055</span><span class="operator">,</span> <span class="number">0x006e</span><span class="operator">,</span> <span class="number">0x10e3</span><span class="operator">,</span> <span class="number">0x03a3</span> };
<span class="type">QString</span> str(data<span class="operator">,</span> <span class="number">4</span>);
</pre>
<p>QString makes a deep copy of the <a href="qchar.html">QChar</a>
data, so you can modify it later without experiencing side effects.
(If for performance reasons you don't want to take a deep copy of
the character data, use <a href="qstring.html#fromRawData">QString.fromRawData</a>() instead.)</p>
<p>Another approach is to set the size of the string using <a href="qstring.html#resize">resize</a>() and to initialize the data
character per character. QString uses 0-based indexes, just like
C++ arrays. To access the character at a particular index position,
you can use <a href="qstring.html#operator-5b-5d">operator[]</a>().
On non-const strings, <a href="qstring.html#operator-5b-5d">operator[]</a>() returns a reference
to a character that can be used on the left side of an assignment.
For example:</p>
<pre class="cpp">
<span class="type">QString</span> str;
str<span class="operator">.</span>resize(<span class="number">4</span>);
str<span class="operator">[</span><span class="number">0</span><span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="qchar.html">QChar</a></span>(<span class="char">'U'</span>);
str<span class="operator">[</span><span class="number">1</span><span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="qchar.html">QChar</a></span>(<span class="char">'n'</span>);
str<span class="operator">[</span><span class="number">2</span><span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="qchar.html">QChar</a></span>(<span class="number">0x10e3</span>);
str<span class="operator">[</span><span class="number">3</span><span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="qchar.html">QChar</a></span>(<span class="number">0x03a3</span>);
</pre>
<p>For read-only access, an alternative syntax is to use the
<a href="qstring.html#at">at</a>() function:</p>
<pre class="cpp">
<span class="type">QString</span> str;
<span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator"><</span> str<span class="operator">.</span>size(); <span class="operator">+</span><span class="operator">+</span>i) {
<span class="keyword">if</span> (str<span class="operator">.</span>at(i) <span class="operator">></span><span class="operator">=</span> <span class="type"><a href="qchar.html">QChar</a></span>(<span class="char">'a'</span>) <span class="operator">&</span><span class="operator">&</span> str<span class="operator">.</span>at(i) <span class="operator"><</span><span class="operator">=</span> <span class="type"><a href="qchar.html">QChar</a></span>(<span class="char">'f'</span>))
<a href="qtcore.html#qDebug">qDebug</a>() <span class="operator"><</span><span class="operator"><</span> <span class="string">"Found character in range [a-f]"</span>;
}
</pre>
<p>The <a href="qstring.html#at">at</a>() function can be faster
than <a href="qstring.html#operator-5b-5d">operator[]</a>(),
because it never causes a <a href="implicit-sharing.html#deep-copy">deep copy</a> to occur.
Alternatively, use the <a href="qstring.html#left">left</a>(),
<a href="qstring.html#right">right</a>(), or <a href="qstring.html#mid">mid</a>() functions to extract several
characters at a time.</p>
<p>A QString can embed '\0' characters (<a href="qchar.html#SpecialCharacter-enum">QChar.Null</a>). The <a href="qstring.html#size">size</a>() function always returns the size of
the whole string, including embedded '\0' characters.</p>
<p>After a call to the <a href="qstring.html#resize">resize</a>()
function, newly allocated characters have undefined values. To set
all the characters in the string to a particular value, use the
<a href="qstring.html#fill">fill</a>() function.</p>
<p>QString provides dozens of overloads designed to simplify string
usage. For example, if you want to compare a QString with a string
literal, you can write code like this and it will work as
expected:</p>
<pre class="cpp">
<span class="type">QString</span> str;
<span class="keyword">if</span> (str <span class="operator">=</span><span class="operator">=</span> <span class="string">"auto"</span> <span class="operator">|</span><span class="operator">|</span> str <span class="operator">=</span><span class="operator">=</span> <span class="string">"extern"</span>
<span class="operator">|</span><span class="operator">|</span> str <span class="operator">=</span><span class="operator">=</span> <span class="string">"static"</span> <span class="operator">|</span><span class="operator">|</span> str <span class="operator">=</span><span class="operator">=</span> <span class="string">"register"</span>) {
<span class="comment">// ...</span>
}
</pre>
<p>You can also pass string literals to functions that take
QStrings as arguments, invoking the QString(const char *)
constructor. Similarly, you can pass a QString to a function that
takes a <tt>const char *</tt> argument using the <a href="qtcore.html#qPrintable">qPrintable</a>() macro which returns the
given QString as a <tt>const char *</tt>. This is equivalent to
calling <QString>.<a href="qstring.html#toLocal8Bit">toLocal8Bit</a>().<a href="qstring.html#constData">constData</a>().</p>
<a id="manipulating-string-data" name="manipulating-string-data" />
<h3>Manipulating String Data</h3>
<p>QString provides the following basic functions for modifying the
character data: <a href="qstring.html#append">append</a>(),
<a href="qstring.html#prepend">prepend</a>(), <a href="qstring.html#insert">insert</a>(), <a href="qstring.html#replace">replace</a>(), and <a href="qstring.html#remove">remove</a>(). For example:</p>
<pre class="cpp">
<span class="type">QString</span> str <span class="operator">=</span> <span class="string">"and"</span>;
str<span class="operator">.</span>prepend(<span class="string">"rock "</span>); <span class="comment">// str == "rock and"</span>
str<span class="operator">.</span>append(<span class="string">" roll"</span>); <span class="comment">// str == "rock and roll"</span>
str<span class="operator">.</span>replace(<span class="number">5</span><span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="string">"&"</span>); <span class="comment">// str == "rock & roll"</span>
</pre>
<p>If you are building a QString gradually and know in advance
approximately how many characters the QString will contain, you can
call <a href="qstring.html#reserve">reserve</a>(), asking QString
to preallocate a certain amount of memory. You can also call
<a href="qstring.html#capacity">capacity</a>() to find out how much
memory QString actually allocated.</p>
<p>The <a href="qstring.html#replace">replace</a>() and <a href="qstring.html#remove">remove</a>() functions' first two arguments
are the position from which to start erasing and the number of
characters that should be erased. If you want to replace all
occurrences of a particular substring with another, use one of the
two-parameter <a href="qstring.html#replace">replace</a>()
overloads.</p>
<p>A frequent requirement is to remove whitespace characters from a
string ('\n', '\t', ' ', etc.). If you want to remove whitespace
from both ends of a QString, use the <a href="qstring.html#trimmed">trimmed</a>() function. If you want to
remove whitespace from both ends and replace multiple consecutive
whitespaces with a single space character within the string, use
<a href="qstring.html#simplified">simplified</a>().</p>
<p>If you want to find all occurrences of a particular character or
substring in a QString, use the <a href="qstring.html#indexOf">indexOf</a>() or <a href="qstring.html#lastIndexOf">lastIndexOf</a>() functions. The former
searches forward starting from a given index position, the latter
searches backward. Both return the index position of the character
or substring if they find it; otherwise, they return -1. For
example, here's a typical loop that finds all occurrences of a
particular substring:</p>
<pre class="cpp">
<span class="type">QString</span> str <span class="operator">=</span> <span class="string">"We must be <b>bold</b>, very <b>bold</b>"</span>;
<span class="type">int</span> j <span class="operator">=</span> <span class="number">0</span>;
<span class="keyword">while</span> ((j <span class="operator">=</span> str<span class="operator">.</span>indexOf(<span class="string">"<b>"</span><span class="operator">,</span> j)) <span class="operator">!</span><span class="operator">=</span> <span class="operator">-</span><span class="number">1</span>) {
<a href="qtcore.html#qDebug">qDebug</a>() <span class="operator"><</span><span class="operator"><</span> <span class="string">"Found <b> tag at index position"</span> <span class="operator"><</span><span class="operator"><</span> j;
<span class="operator">+</span><span class="operator">+</span>j;
}
</pre>
<p>QString provides many functions for converting numbers into
strings and strings into numbers. See the <a href="qstring.html#arg">arg</a>() functions, the <a href="qstring.html#setNum">setNum</a>() functions, the <a href="qstring.html#number">number</a>() static functions, and the
<a href="qstring.html#toInt">toInt</a>(), <a href="qstring.html#toDouble">toDouble</a>(), and similar functions.</p>
<p>To get an upper- or lowercase version of a string use <a href="qstring.html#toUpper">toUpper</a>() or <a href="qstring.html#toLower">toLower</a>().</p>
<p>Lists of strings are handled by the <a href="qstringlist.html">QStringList</a> class. You can split a string
into a list of strings using the <a href="qstring.html#split">split</a>() function, and join a list of
strings into a single string with an optional separator using
<a href="qstringlist.html#join">QStringList.join</a>(). You can
obtain a list of strings from a string list that contain a
particular substring or that match a particular <a href="qregexp.html">QRegExp</a> using the <a href="qstringlist.html#filter">QStringList.filter</a>() function.</p>
<a id="querying-string-data" name="querying-string-data" />
<h3>Querying String Data</h3>
<p>If you want to see if a QString starts or ends with a particular
substring use <a href="qstring.html#startsWith">startsWith</a>() or
<a href="qstring.html#endsWith">endsWith</a>(). If you simply want
to check whether a QString contains a particular character or
substring, use the <a href="qstring.html#contains">contains</a>()
function. If you want to find out how many times a particular
character or substring occurs in the string, use <a href="qstring.html#count">count</a>().</p>
<p>QStrings can be compared using overloaded operators such as
<a href="qstring.html#operator-lt">operator<</a>(), <a href="qstring.html#operator-lt-eq">operator<=</a>(), <a href="qstring.html#operator-eq-eq">operator==</a>(), <a href="qstring.html#operator-gt-eq">operator>=</a>(), and so on. Note
that the comparison is based exclusively on the numeric Unicode
values of the characters. It is very fast, but is not what a human
would expect; the <a href="qstring.html#localeAwareCompare">QString.localeAwareCompare</a>()
function is a better choice for sorting user-interface strings.</p>
<p>To obtain a pointer to the actual character data, call <a href="qstring.html#data">data</a>() or <a href="qstring.html#constData">constData</a>(). These functions return a
pointer to the beginning of the <a href="qchar.html">QChar</a>
data. The pointer is guaranteed to remain valid until a non-const
function is called on the QString.</p>
<a id="converting-between-8-bit-strings-and-unicode-strings" name="converting-between-8-bit-strings-and-unicode-strings" />
<h3>Converting Between 8-Bit Strings and Unicode Strings</h3>
<p>QString provides the following four functions that return a
<tt>const char *</tt> version of the string as <a href="qbytearray.html">QByteArray</a>: <a href="qstring.html#toAscii">toAscii</a>(), <a href="qstring.html#toLatin1">toLatin1</a>(), <a href="qstring.html#toUtf8">toUtf8</a>(), and <a href="qstring.html#toLocal8Bit">toLocal8Bit</a>().</p>
<ul>
<li><a href="qstring.html#toAscii">toAscii</a>() returns an 8-bit
string encoded using the codec specified by
QTextCodec.codecForCStrings (by default, that is Latin 1).</li>
<li><a href="qstring.html#toLatin1">toLatin1</a>() returns a
Latin-1 (ISO 8859-1) encoded 8-bit string.</li>
<li><a href="qstring.html#toUtf8">toUtf8</a>() returns a UTF-8
encoded 8-bit string. UTF-8 is a superset of US-ASCII (ANSI
X3.4-1986) that supports the entire Unicode character set through
multibyte sequences.</li>
<li><a href="qstring.html#toLocal8Bit">toLocal8Bit</a>() returns an
8-bit string using the system's local encoding.</li>
</ul>
<p>To convert from one of these encodings, QString provides
<a href="qstring.html#fromAscii">fromAscii</a>(), <a href="qstring.html#fromLatin1">fromLatin1</a>(), <a href="qstring.html#fromUtf8">fromUtf8</a>(), and <a href="qstring.html#fromLocal8Bit">fromLocal8Bit</a>(). Other encodings
are supported through the <a href="qtextcodec.html">QTextCodec</a>
class.</p>
<p>As mentioned above, QString provides a lot of functions and
operators that make it easy to interoperate with <tt>const char
*</tt> strings. But this functionality is a double-edged sword: It
makes QString more convenient to use if all strings are US-ASCII or
Latin-1, but there is always the risk that an implicit conversion
from or to <tt>const char *</tt> is done using the wrong 8-bit
encoding. To minimize these risks, you can turn off these implicit
conversions by defining the following two preprocessor symbols:</p>
<ul>
<li><tt>QT_NO_CAST_FROM_ASCII</tt> disables automatic conversions
from C string literals and pointers to Unicode.</li>
<li><tt>QT_NO_CAST_TO_ASCII</tt> disables automatic conversion from
QString to C strings.</li>
</ul>
<p>One way to define these preprocessor symbols globally for your
application is to add the following entry to your <a href="qmake-project-files.html">qmake project file</a>:</p>
<pre class="cpp">
DEFINES <span class="operator">+</span><span class="operator">=</span> QT_NO_CAST_FROM_ASCII \
QT_NO_CAST_TO_ASCII
</pre>
<p>You then need to explicitly call <a href="qstring.html#fromAscii">fromAscii</a>(), <a href="qstring.html#fromLatin1">fromLatin1</a>(), <a href="qstring.html#fromUtf8">fromUtf8</a>(), or <a href="qstring.html#fromLocal8Bit">fromLocal8Bit</a>() to construct a
QString from an 8-bit string, or use the lightweight <a href="qlatin1string.html">QLatin1String</a> class, for example:</p>
<pre class="cpp">
<span class="type">QString</span> url <span class="operator">=</span> QLatin1String(<span class="string">"http://www.unicode.org/"</span>);
</pre>
<p>Similarly, you must call <a href="qstring.html#toAscii">toAscii</a>(), <a href="qstring.html#toLatin1">toLatin1</a>(), <a href="qstring.html#toUtf8">toUtf8</a>(), or <a href="qstring.html#toLocal8Bit">toLocal8Bit</a>() explicitly to convert
the QString to an 8-bit string. (Other encodings are supported
through the <a href="qtextcodec.html">QTextCodec</a> class.)</p>
<table class="generic" width="100 %">
<thead>
<tr class="qt-style">
<th>Note for C Programmers</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>Due to C++'s type system and the fact that QString is <a href="implicit-sharing.html#implicitly-shared">implicitly shared</a>,
QStrings may be treated like <tt>int</tt>s or other basic types.
For example:
<pre class="cpp">
<span class="type">QString</span> Widget<span class="operator">.</span>boolToString(<span class="type">bool</span> b)
{
<span class="type">QString</span> result;
<span class="keyword">if</span> (b)
result <span class="operator">=</span> <span class="string">"True"</span>;
<span class="keyword">else</span>
result <span class="operator">=</span> <span class="string">"False"</span>;
<span class="keyword">return</span> result;
}
</pre>
<p>The <tt>result</tt> variable, is a normal variable allocated on
the stack. When <tt>return</tt> is called, and because we're
returning by value, the copy constructor is called and a copy of
the string is returned. No actual copying takes place thanks to the
implicit sharing.</p>
</td>
</tr>
</table>
<a id="distinction-between-null-and-empty-strings" name="distinction-between-null-and-empty-strings" />
<h3>Distinction Between Null and Empty Strings</h3>
<p>For historical reasons, QString distinguishes between a null
string and an empty string. A <i>null</i> string is a string that
is initialized using QString's default constructor or by passing
(const char *)0 to the constructor. An <i>empty</i> string is any
string with size 0. A null string is always empty, but an empty
string isn't necessarily null:</p>
<pre class="cpp">
<span class="type">QString</span>()<span class="operator">.</span>isNull(); <span class="comment">// returns true</span>
<span class="type">QString</span>()<span class="operator">.</span>isEmpty(); <span class="comment">// returns true</span>
<span class="type">QString</span>(<span class="string">""</span>)<span class="operator">.</span>isNull(); <span class="comment">// returns false</span>
<span class="type">QString</span>(<span class="string">""</span>)<span class="operator">.</span>isEmpty(); <span class="comment">// returns true</span>
<span class="type">QString</span>(<span class="string">"abc"</span>)<span class="operator">.</span>isNull(); <span class="comment">// returns false</span>
<span class="type">QString</span>(<span class="string">"abc"</span>)<span class="operator">.</span>isEmpty(); <span class="comment">// returns false</span>
</pre>
<p>All functions except <a href="qstring.html#isNull">isNull</a>()
treat null strings the same as empty strings. For example, <a href="qstring.html#toAscii">toAscii</a>().<a href="qstring.html#constData">constData</a>() returns a pointer to a
'\0' character for a null string (<i>not</i> a null pointer), and
<a href="qstring.html#QString">QString</a>() compares equal to
QString(""). We recommend that you always use the <a href="qstring.html#isEmpty">isEmpty</a>() function and avoid <a href="qstring.html#isNull">isNull</a>().</p>
<a id="argument-formats" name="argument-formats" />
<h3>Argument Formats</h3>
<p>In member functions where an argument <i>format</i> can be
specified (e.g., <a href="qstring.html#arg">arg</a>(), <a href="qstring.html#number">number</a>()), the argument <i>format</i> can
be one of the following:</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>Format</th>
<th>Meaning</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td><tt>e</tt></td>
<td>format as [-]9.9e[+|-]999</td>
</tr>
<tr class="even" valign="top">
<td><tt>E</tt></td>
<td>format as [-]9.9E[+|-]999</td>
</tr>
<tr class="odd" valign="top">
<td><tt>f</tt></td>
<td>format as [-]9.9</td>
</tr>
<tr class="even" valign="top">
<td><tt>g</tt></td>
<td>use <tt>e</tt> or <tt>f</tt> format, whichever is the most
concise</td>
</tr>
<tr class="odd" valign="top">
<td><tt>G</tt></td>
<td>use <tt>E</tt> or <tt>f</tt> format, whichever is the most
concise</td>
</tr>
</table>
<p>A <i>precision</i> is also specified with the argument
<i>format</i>. For the 'e', 'E', and 'f' formats, the
<i>precision</i> represents the number of digits <i>after</i> the
decimal point. For the 'g' and 'G' formats, the <i>precision</i>
represents the maximum number of significant digits (trailing
zeroes are omitted).</p>
<a id="more-efficient-string-construction" name="more-efficient-string-construction" />
<h3>More Efficient String Construction</h3>
<p>Using the QString <tt>'+'</tt> operator, it is easy to construct
a complex string from multiple substrings. You will often write
code like this:</p>
<pre class="cpp">
<span class="type">QString</span> foo;
<span class="type">QString</span> type <span class="operator">=</span> <span class="string">"long"</span>;
foo<span class="operator">-</span><span class="operator">></span>setText(QLatin1String(<span class="string">"vector<"</span>) <span class="operator">+</span> type <span class="operator">+</span> QLatin1String(<span class="string">">.iterator"</span>));
<span class="keyword">if</span> (foo<span class="operator">.</span>startsWith(<span class="string">"("</span> <span class="operator">+</span> type <span class="operator">+</span> <span class="string">") 0x"</span>))
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
</pre>
<p>There is nothing wrong with either of these string
constructions, but there are a few hidden inefficiencies. Beginning
with Qt 4.6, you can eliminate them.</p>
<p>First, multiple uses of the <tt>'+'</tt> operator usually means
multiple memory allocations. When concatenating <i>n</i>
substrings, where <i>n > 2</i>, there can be as many as <i>n -
1</i> calls to the memory allocator.</p>
<p>Second, <a href="qlatin1string.html">QLatin1String</a> does not
store its length internally but calls <a href="qtcore.html#qstrlen">qstrlen</a>() when it needs to know its
length.</p>
<p>In 4.6, an internal template class <tt>QStringBuilder</tt> has
been added along with a few helper functions. This class is marked
internal and does not appear in the documentation, because you
aren't meant to instantiate it in your code. Its use will be
automatic, as described below. The class is found in
<tt>src/corelib/tools/qstringbuilder.cpp</tt> if you want to have a
look at it.</p>
<p><tt>QStringBuilder</tt> uses expression templates and
reimplements the <tt>'%'</tt> operator so that when you use
<tt>'%'</tt> for string concatenation instead of <tt>'+'</tt>,
multiple substring concatenations will be postponed until the final
result is about to be assigned to a QString. At this point, the
amount of memory required for the final result is known. The memory
allocator is then called <i>once</i> to get the required space, and
the substrings are copied into it one by one.</p>
<p><tt>QLatin1Literal</tt> is a second internal class that can
replace <a href="qlatin1string.html">QLatin1String</a>, which can't
be changed for compatibility reasons. <tt>QLatin1Literal</tt>
stores its length, thereby saving time when <tt>QStringBuilder</tt>
computes the amount of memory required for the final string.</p>
<p>Additional efficiency is gained by inlining and reduced
reference counting (the QString created from a
<tt>QStringBuilder</tt> typically has a ref count of 1, whereas
<a href="qstring.html#append">QString.append</a>() needs an extra
test).</p>
<p>There are three ways you can access this improved method of
string construction. The straightforward way is to include
<tt>QStringBuilder</tt> wherever you want to use it, and use the
<tt>'%'</tt> operator instead of <tt>'+'</tt> when concatenating
strings:</p>
<pre class="cpp">
<span class="preprocessor">#include <QStringBuilder></span>
<span class="type">QString</span> hello(<span class="string">"hello"</span>);
<span class="type"><a href="qstringref.html">QStringRef</a></span> el(<span class="operator">&</span>hello<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">3</span>);
QLatin1String world(<span class="string">"world"</span>);
<span class="type">QString</span> message <span class="operator">=</span> hello <span class="operator">%</span> el <span class="operator">%</span> world <span class="operator">%</span> <span class="type"><a href="qchar.html">QChar</a></span>(<span class="char">'!'</span>);
</pre>
<p>A more global approach which is the most convenient but not
entirely source compatible, is to this define in your .pro
file:</p>
<pre class="cpp">
DEFINES <span class="operator">*</span><span class="operator">=</span> QT_USE_QSTRINGBUILDER
</pre>
<p>and the <tt>'+'</tt> will automatically be performed as the
<tt>QStringBuilder</tt> <tt>'%'</tt> everywhere.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="NormalizationForm-enum" />QString.NormalizationForm</h3><p>This enum describes the various normalized forms of Unicode
text.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QString.NormalizationForm_D</tt></td>
<td class="topAlign"><tt>0</tt></td>
<td class="topAlign">Canonical Decomposition</td>
</tr>
<tr>
<td class="topAlign"><tt>QString.NormalizationForm_C</tt></td>
<td class="topAlign"><tt>1</tt></td>
<td class="topAlign">Canonical Decomposition followed by Canonical
Composition</td>
</tr>
<tr>
<td class="topAlign"><tt>QString.NormalizationForm_KD</tt></td>
<td class="topAlign"><tt>2</tt></td>
<td class="topAlign">Compatibility Decomposition</td>
</tr>
<tr>
<td class="topAlign"><tt>QString.NormalizationForm_KC</tt></td>
<td class="topAlign"><tt>3</tt></td>
<td class="topAlign">Compatibility Decomposition followed by
Canonical Composition</td>
</tr>
</table>
<p><b>See also</b> <a href="qstring.html#normalized">normalized</a>() and <a href="http://www.unicode.org/reports/tr15/">Unicode Standard Annex
#15</a>.</p>
<h3 class="fn"><a name="SectionFlag-enum" />QString.SectionFlag</h3><p>This enum specifies flags that can be used to affect various
aspects of the <a href="qstring.html#section">section</a>()
function's behavior with respect to separators and empty
fields.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QString.SectionDefault</tt></td>
<td class="topAlign"><tt>0x00</tt></td>
<td class="topAlign">Empty fields are counted, leading and trailing
separators are not included, and the separator is compared case
sensitively.</td>
</tr>
<tr>
<td class="topAlign"><tt>QString.SectionSkipEmpty</tt></td>
<td class="topAlign"><tt>0x01</tt></td>
<td class="topAlign">Treat empty fields as if they don't exist,
i.e. they are not considered as far as <i>start</i> and <i>end</i>
are concerned.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QString.SectionIncludeLeadingSep</tt></td>
<td class="topAlign"><tt>0x02</tt></td>
<td class="topAlign">Include the leading separator (if any) in the
result string.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QString.SectionIncludeTrailingSep</tt></td>
<td class="topAlign"><tt>0x04</tt></td>
<td class="topAlign">Include the trailing separator (if any) in the
result string.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QString.SectionCaseInsensitiveSeps</tt></td>
<td class="topAlign"><tt>0x08</tt></td>
<td class="topAlign">Compare the separator case-insensitively.</td>
</tr>
</table>
<p>The SectionFlags type is a typedef for <a href="qflags.html">QFlags</a><SectionFlag>. It stores an OR
combination of SectionFlag values.</p>
<p><b>See also</b> <a href="qstring.html#section">section</a>().</p>
<h3 class="fn"><a name="SplitBehavior-enum" />QString.SplitBehavior</h3><p>This enum specifies how the <a href="qstring.html#split">split</a>() function should behave with
respect to empty strings.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QString.KeepEmptyParts</tt></td>
<td class="topAlign"><tt>0</tt></td>
<td class="topAlign">If a field is empty, keep it in the
result.</td>
</tr>
<tr>
<td class="topAlign"><tt>QString.SkipEmptyParts</tt></td>
<td class="topAlign"><tt>1</tt></td>
<td class="topAlign">If a field is empty, don't include it in the
result.</td>
</tr>
</table>
<p><b>See also</b> <a href="qstring.html#split">split</a>().</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QString" />QString.__init__ (<i>self</i>)</h3><p>Constructs a null string. Null strings are also empty.</p>
<p><b>See also</b> <a href="qstring.html#isEmpty">isEmpty</a>().</p>
<h3 class="fn"><a name="QString" />QString.__init__ (<i>self</i>, <a href="qkeysequence.html">QKeySequence</a>)</h3><p>This method is only available if the QtGui module is imported.</p><p>Constructs a null string. Null strings are also empty.</p>
<p><b>See also</b> <a href="qstring.html#isEmpty">isEmpty</a>().</p>
<h3 class="fn"><a name="QString" />QString.__init__ (<i>self</i>, <a href="qscriptstring.html">QScriptString</a>)</h3><p>This method is only available if the QtScript module is imported.</p><p>Constructs a null string. Null strings are also empty.</p>
<p><b>See also</b> <a href="qstring.html#isEmpty">isEmpty</a>().</p>
<h3 class="fn"><a name="QString-2" />QString.__init__ (<i>self</i>, int <i>size</i>, QChar <i>c</i>)</h3><p>Constructs a string initialized with the first <i>size</i>
characters of the <a href="qchar.html">QChar</a> array
<i>unicode</i>.</p>
<p><a href="qstring.html">QString</a> makes a deep copy of the
string data. The unicode data is copied as is and the Byte Order
Mark is preserved if present.</p>
<h3 class="fn"><a name="QString-3" />QString.__init__ (<i>self</i>, QString <i>s</i>)</h3><p>Constructs a string initialized with the characters of the
<a href="qchar.html">QChar</a> array <i>unicode</i>, which must be
terminated with a 0.</p>
<p><a href="qstring.html">QString</a> makes a deep copy of the
string data. The unicode data is copied as is and the Byte Order
Mark is preserved if present.</p>
<p>This function was introduced in Qt 4.7.</p>
<h3 class="fn"><a name="QString-4" />QString.__init__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>a</i>)</h3><p>Constructs a string of size 1 containing the character
<i>ch</i>.</p>
<h3 class="fn"><a name="QString-5" />QString.__init__ (<i>self</i>, <a href="quuid.html">QUuid</a>)</h3><p>Constructs a string of the given <i>size</i> with every
character set to <i>ch</i>.</p>
<p><b>See also</b> <a href="qstring.html#fill">fill</a>().</p>
<h3 class="fn"><a name="append" />QString QString.append (<i>self</i>, QString <i>s</i>)</h3><p>Appends the string <i>str</i> onto the end of this string.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> x <span class="operator">=</span> <span class="string">"free"</span>;
<span class="type"><a href="qstring.html">QString</a></span> y <span class="operator">=</span> <span class="string">"dom"</span>;
x<span class="operator">.</span>append(y);
<span class="comment">// x == "freedom"</span>
</pre>
<p>This is the same as using the <a href="qstring.html#insert">insert</a>() function:</p>
<pre class="cpp">
x<span class="operator">.</span>insert(x<span class="operator">.</span>size()<span class="operator">,</span> y);
</pre>
<p>The append() function is typically very fast (<a href="containers.html#constant-time">constant time</a>), because
<a href="qstring.html">QString</a> preallocates extra space at the
end of the string data so it can grow without reallocating the
entire string each time.</p>
<p><b>See also</b> <a href="qstring.html#operator-2b-eq">operator+=</a>(), <a href="qstring.html#prepend">prepend</a>(), and <a href="qstring.html#insert">insert</a>().</p>
<h3 class="fn"><a name="append-2" />QString QString.append (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>)</h3><p>Appends the given string <i>reference</i> to this string and
returns the result.</p>
<p>This function was introduced in Qt 4.4.</p>
<h3 class="fn"><a name="append-3" />QString QString.append (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>s</i>)</h3><p>This function overloads <a href="qstring.html#append">append</a>().</p>
<p>Appends the Latin-1 string <i>str</i> to this string.</p>
<h3 class="fn"><a name="arg" />QString QString.arg (<i>self</i>, int <i>a</i>, int <i>fieldWidth</i> = 0, int <i>base</i> = 10, QChar <i>fillChar</i> = QLatin1Char(' '))</h3><p>Returns a copy of this string with the lowest numbered place
marker replaced by string <i>a</i>, i.e., <tt>%1</tt>, <tt>%2</tt>,
..., <tt>%99</tt>.</p>
<p><i>fieldWidth</i> specifies the minimum amount of space that
argument <i>a</i> shall occupy. If <i>a</i> requires less space
than <i>fieldWidth</i>, it is padded to <i>fieldWidth</i> with
character <i>fillChar</i>. A positive <i>fieldWidth</i> produces
right-aligned text. A negative <i>fieldWidth</i> produces
left-aligned text.</p>
<p>This example shows how we might create a <tt>status</tt> string
for reporting progress while processing a list of files:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> i; <span class="comment">// current file's number</span>
<span class="type"><a href="qstring.html">QString</a></span> total; <span class="comment">// number of files to process</span>
<span class="type"><a href="qstring.html">QString</a></span> fileName; <span class="comment">// current file's name</span>
<span class="type"><a href="qstring.html">QString</a></span> status <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="string">"Processing file %1 of %2: %3"</span>)
<span class="operator">.</span>arg(i)<span class="operator">.</span>arg(total)<span class="operator">.</span>arg(fileName);
</pre>
<p>First, <tt>arg(i)</tt> replaces <tt>%1</tt>. Then
<tt>arg(total)</tt> replaces <tt>%2</tt>. Finally,
<tt>arg(fileName)</tt> replaces <tt>%3</tt>.</p>
<p>One advantage of using arg() over <a href="qstring.html#sprintf">sprintf</a>() is that the order of the
numbered place markers can change, if the application's strings are
translated into other languages, but each arg() will still replace
the lowest numbered unreplaced place marker, no matter where it
appears. Also, if place marker <tt>%i</tt> appears more than once
in the string, the arg() replaces all of them.</p>
<p>If there is no unreplaced place marker remaining, a warning
message is output and the result is undefined. Place marker numbers
must be in the range 1 to 99.</p>
<h3 class="fn"><a name="arg-2" />QString QString.arg (<i>self</i>, float <i>a</i>, int <i>fieldWidth</i> = 0, str <i>format</i> = 'g', int <i>precision</i> = -1, QChar <i>fillChar</i> = QLatin1Char(' '))</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p>This is the same as <tt>str.arg(a1).arg(a2)</tt>, except that
the strings <i>a1</i> and <i>a2</i> are replaced in one pass. This
can make a difference if <i>a1</i> contains e.g. <tt>%1</tt>:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str;
str <span class="operator">=</span> <span class="string">"%1 %2"</span>;
str<span class="operator">.</span>arg(<span class="string">"%1f"</span><span class="operator">,</span> <span class="string">"Hello"</span>); <span class="comment">// returns "%1f Hello"</span>
str<span class="operator">.</span>arg(<span class="string">"%1f"</span>)<span class="operator">.</span>arg(<span class="string">"Hello"</span>); <span class="comment">// returns "Hellof %2"</span>
</pre>
<h3 class="fn"><a name="arg-3" />QString QString.arg (<i>self</i>, int <i>a</i>, int <i>fieldWidth</i> = 0, int <i>base</i> = 10, QChar <i>fillChar</i> = QLatin1Char(' '))</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p>This is the same as calling
<tt>str.arg(a1).arg(a2).arg(a3)</tt>, except that the strings
<i>a1</i>, <i>a2</i> and <i>a3</i> are replaced in one pass.</p>
<h3 class="fn"><a name="arg-4" />QString QString.arg (<i>self</i>, int <i>a</i>, int <i>fieldWidth</i> = 0, int <i>base</i> = 10, QChar <i>fillChar</i> = QLatin1Char(' '))</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p>This is the same as calling
<tt>str.arg(a1).arg(a2).arg(a3).arg(a4)</tt>, except that the
strings <i>a1</i>, <i>a2</i>, <i>a3</i> and <i>a4</i> are replaced
in one pass.</p>
<h3 class="fn"><a name="arg-5" />QString QString.arg (<i>self</i>, QString <i>a</i>, int <i>fieldWidth</i> = 0, QChar <i>fillChar</i> = QLatin1Char(' '))</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p>This is the same as calling
<tt>str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5)</tt>, except that
the strings <i>a1</i>, <i>a2</i>, <i>a3</i>, <i>a4</i>, and
<i>a5</i> are replaced in one pass.</p>
<h3 class="fn"><a name="arg-6" />QString QString.arg (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>)</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p>This is the same as calling
<tt>str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6))</tt>,
except that the strings <i>a1</i>, <i>a2</i>, <i>a3</i>, <i>a4</i>,
<i>a5</i>, and <i>a6</i> are replaced in one pass.</p>
<h3 class="fn"><a name="arg-7" />QString QString.arg (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>)</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p>This is the same as calling
<tt>str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7)</tt>,
except that the strings <i>a1</i>, <i>a2</i>, <i>a3</i>, <i>a4</i>,
<i>a5</i>, <i>a6</i>, and <i>a7</i> are replaced in one pass.</p>
<h3 class="fn"><a name="arg-8" />QString QString.arg (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>)</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p>This is the same as calling
<tt>str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7).arg(a8)</tt>,
except that the strings <i>a1</i>, <i>a2</i>, <i>a3</i>, <i>a4</i>,
<i>a5</i>, <i>a6</i>, <i>a7</i>, and <i>a8</i> are replaced in one
pass.</p>
<h3 class="fn"><a name="arg-9" />QString QString.arg (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>, QString <i>a5</i>)</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p>This is the same as calling
<tt>str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7).arg(a8).arg(a9)</tt>,
except that the strings <i>a1</i>, <i>a2</i>, <i>a3</i>, <i>a4</i>,
<i>a5</i>, <i>a6</i>, <i>a7</i>, <i>a8</i>, and <i>a9</i> are
replaced in one pass.</p>
<h3 class="fn"><a name="arg-10" />QString QString.arg (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>, QString <i>a5</i>, QString <i>a6</i>)</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p>The <i>a</i> argument is expressed in base <i>base</i>, which is
10 by default and must be between 2 and 36. For bases other than
10, <i>a</i> is treated as an unsigned integer.</p>
<p><i>fieldWidth</i> specifies the minimum amount of space that
<i>a</i> is padded to and filled with the character
<i>fillChar</i>. A positive value produces right-aligned text; a
negative value produces left-aligned text.</p>
<p>The '%' can be followed by an 'L', in which case the sequence is
replaced with a localized representation of <i>a</i>. The
conversion uses the default locale, set by <a href="qlocale.html#setDefault">QLocale.setDefault</a>(). If no default
locale was specified, the "C" locale is used. The 'L' flag is
ignored if <i>base</i> is not 10.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str;
str <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="string">"Decimal 63 is %1 in hexadecimal"</span>)
<span class="operator">.</span>arg(<span class="number">63</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">16</span>);
<span class="comment">// str == "Decimal 63 is 3f in hexadecimal"</span>
<span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>setDefault(<span class="type"><a href="qlocale.html">QLocale</a></span>(<span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>English<span class="operator">,</span> <span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>UnitedStates));
str <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="string">"%1 %L2 %L3"</span>)
<span class="operator">.</span>arg(<span class="number">12345</span>)
<span class="operator">.</span>arg(<span class="number">12345</span>)
<span class="operator">.</span>arg(<span class="number">12345</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">16</span>);
<span class="comment">// str == "12345 12,345 3039"</span>
</pre>
<p>If <i>fillChar</i> is '0' (the number 0, ASCII 48), the locale's
zero is used. For negative numbers, zero padding might appear
before the minus sign.</p>
<h3 class="fn"><a name="arg-11" />QString QString.arg (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>, QString <i>a5</i>, QString <i>a6</i>, QString <i>a7</i>)</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p>The <i>base</i> argument specifies the base to use when
converting the integer <i>a</i> into a string. The base must be
between 2 and 36.</p>
<p>If <i>fillChar</i> is '0' (the number 0, ASCII 48), the locale's
zero is used. For negative numbers, zero padding might appear
before the minus sign.</p>
<h3 class="fn"><a name="arg-12" />QString QString.arg (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>, QString <i>a5</i>, QString <i>a6</i>, QString <i>a7</i>, QString <i>a8</i>)</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p><i>fieldWidth</i> specifies the minimum amount of space that
<i>a</i> is padded to and filled with the character
<i>fillChar</i>. A positive value produces right-aligned text; a
negative value produces left-aligned text.</p>
<p>The <i>a</i> argument is expressed in the given <i>base</i>,
which is 10 by default and must be between 2 and 36.</p>
<p>The '%' can be followed by an 'L', in which case the sequence is
replaced with a localized representation of <i>a</i>. The
conversion uses the default locale. The default locale is
determined from the system's locale settings at application
startup. It can be changed using <a href="qlocale.html#setDefault">QLocale.setDefault</a>(). The 'L' flag
is ignored if <i>base</i> is not 10.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str;
str <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="string">"Decimal 63 is %1 in hexadecimal"</span>)
<span class="operator">.</span>arg(<span class="number">63</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">16</span>);
<span class="comment">// str == "Decimal 63 is 3f in hexadecimal"</span>
<span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>setDefault(<span class="type"><a href="qlocale.html">QLocale</a></span>(<span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>English<span class="operator">,</span> <span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>UnitedStates));
str <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="string">"%1 %L2 %L3"</span>)
<span class="operator">.</span>arg(<span class="number">12345</span>)
<span class="operator">.</span>arg(<span class="number">12345</span>)
<span class="operator">.</span>arg(<span class="number">12345</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">16</span>);
<span class="comment">// str == "12345 12,345 3039"</span>
</pre>
<p>If <i>fillChar</i> is '0' (the number 0, ASCII 48), the locale's
zero is used. For negative numbers, zero padding might appear
before the minus sign.</p>
<h3 class="fn"><a name="arg-13" />QString QString.arg (<i>self</i>, QString <i>a1</i>, QString <i>a2</i>, QString <i>a3</i>, QString <i>a4</i>, QString <i>a5</i>, QString <i>a6</i>, QString <i>a7</i>, QString <i>a8</i>, QString <i>a9</i>)</h3><p>This function overloads <a href="qstring.html#arg">arg</a>().</p>
<p><i>fieldWidth</i> specifies the minimum amount of space that
<i>a</i> is padded to and filled with the character
<i>fillChar</i>. A positive value produces right-aligned text; a
negative value produces left-aligned text.</p>
<p>The <i>base</i> argument specifies the base to use when
converting the integer <i>a</i> to a string. The base must be
between 2 and 36, with 8 giving octal, 10 decimal, and 16
hexadecimal numbers.</p>
<p>If <i>fillChar</i> is '0' (the number 0, ASCII 48), the locale's
zero is used. For negative numbers, zero padding might appear
before the minus sign.</p>
<h3 class="fn"><a name="at" />QChar QString.at (<i>self</i>, int <i>i</i>)</h3><p>Returns the character at the given index <i>position</i> in the
string.</p>
<p>The <i>position</i> must be a valid index position in the string
(i.e., 0 <= <i>position</i> < <a href="qstring.html#size">size</a>()).</p>
<p><b>See also</b> <a href="qstring.html#operator-5b-5d">operator[]</a>().</p>
<h3 class="fn"><a name="capacity" />int QString.capacity (<i>self</i>)</h3><p>Returns the maximum number of characters that can be stored in
the string without forcing a reallocation.</p>
<p>The sole purpose of this function is to provide a means of fine
tuning <a href="qstring.html">QString</a>'s memory usage. In
general, you will rarely ever need to call this function. If you
want to know how many characters are in the string, call <a href="qstring.html#size">size</a>().</p>
<p><b>See also</b> <a href="qstring.html#reserve">reserve</a>() and
<a href="qstring.html#squeeze">squeeze</a>().</p>
<h3 class="fn"><a name="chop" />QString.chop (<i>self</i>, int <i>n</i>)</h3><p>Removes <i>n</i> characters from the end of the string.</p>
<p>If <i>n</i> is greater than <a href="qstring.html#size">size</a>(), the result is an empty string.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str(<span class="string">"LOGOUT\r\n"</span>);
str<span class="operator">.</span>chop(<span class="number">2</span>);
<span class="comment">// str == "LOGOUT"</span>
</pre>
<p>If you want to remove characters from the <i>beginning</i> of
the string, use <a href="qstring.html#remove">remove</a>()
instead.</p>
<p><b>See also</b> <a href="qstring.html#truncate">truncate</a>(),
<a href="qstring.html#resize">resize</a>(), and <a href="qstring.html#remove">remove</a>().</p>
<h3 class="fn"><a name="clear" />QString.clear (<i>self</i>)</h3><p>Clears the contents of the string and makes it empty.</p>
<p><b>See also</b> <a href="qstring.html#resize">resize</a>() and
<a href="qstring.html#isEmpty">isEmpty</a>().</p>
<h3 class="fn"><a name="compare" />int QString.compare (<i>self</i>, QString <i>s</i>)</h3><p>Compares <i>s1</i> with <i>s2</i> and returns an integer less
than, equal to, or greater than zero if <i>s1</i> is less than,
equal to, or greater than <i>s2</i>.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a>, the
comparison is case sensitive; otherwise the comparison is case
insensitive.</p>
<p>Case sensitive comparison is based exclusively on the numeric
Unicode values of the characters and is very fast, but is not what
a human would expect. Consider sorting user-visible strings with
<a href="qstring.html#localeAwareCompare">localeAwareCompare</a>().</p>
<pre class="cpp">
<span class="type">int</span> x <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span><span class="operator">.</span>compare(<span class="string">"aUtO"</span><span class="operator">,</span> <span class="string">"AuTo"</span><span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>CaseInsensitive); <span class="comment">// x == 0</span>
<span class="type">int</span> y <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span><span class="operator">.</span>compare(<span class="string">"auto"</span><span class="operator">,</span> <span class="string">"Car"</span><span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>CaseSensitive); <span class="comment">// y > 0</span>
<span class="type">int</span> z <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span><span class="operator">.</span>compare(<span class="string">"auto"</span><span class="operator">,</span> <span class="string">"Car"</span><span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>CaseInsensitive); <span class="comment">// z < 0</span>
</pre>
<p>This function was introduced in Qt 4.2.</p>
<p><b>See also</b> <a href="qstring.html#operator-eq-eq">operator==</a>(), <a href="qstring.html#operator-lt">operator<</a>(), and <a href="qstring.html#operator-gt">operator></a>().</p>
<h3 class="fn"><a name="compare-2" />int QString.compare (<i>self</i>, QString <i>s</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i>)</h3><p>This function overloads <a href="qstring.html#compare">compare</a>().</p>
<p>Performs a case sensitive compare of <i>s1</i> and
<i>s2</i>.</p>
<h3 class="fn"><a name="compare-3" />int QString.compare (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>other</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#compare">compare</a>().</p>
<p>Performs a comparison of <i>s1</i> and <i>s2</i>, using the case
sensitivity setting <i>cs</i>.</p>
<p>This function was introduced in Qt 4.2.</p>
<h3 class="fn"><a name="compare-4" />int QString.compare (<i>self</i>, QStringRef <i>ref</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#compare">compare</a>().</p>
<p>Performs a comparison of <i>s1</i> and <i>s2</i>, using the case
sensitivity setting <i>cs</i>.</p>
<p>This function was introduced in Qt 4.2.</p>
<h3 class="fn"><a name="compare-5" />int QString.compare (QString <i>s1</i>, QString <i>s2</i>)</h3><p>This function overloads <a href="qstring.html#compare">compare</a>().</p>
<p>Lexically compares this string with the <i>other</i> string and
returns an integer less than, equal to, or greater than zero if
this string is less than, equal to, or greater than the other
string.</p>
<p>Equivalent to <tt>compare(*this, other)</tt>.</p>
<h3 class="fn"><a name="compare-6" />int QString.compare (QString <i>s1</i>, QString <i>s2</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i>)</h3><p>This function overloads <a href="qstring.html#compare">compare</a>().</p>
<p>Same as compare(*this, <i>other</i>, <i>cs</i>).</p>
<p>This function was introduced in Qt 4.2.</p>
<h3 class="fn"><a name="compare-7" />int QString.compare (QString <i>s1</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s2</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#compare">compare</a>().</p>
<p>Same as compare(*this, <i>other</i>, <i>cs</i>).</p>
<p>This function was introduced in Qt 4.2.</p>
<h3 class="fn"><a name="compare-8" />int QString.compare (<a href="qlatin1string.html">QLatin1String</a> <i>s1</i>, QString <i>s2</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#compare">compare</a>().</p>
<p>Compares the string reference, <i>ref</i>, with the string and
returns an integer less than, equal to, or greater than zero if the
string is less than, equal to, or greater than <i>ref</i>.</p>
<h3 class="fn"><a name="compare-9" />int QString.compare (QString <i>s1</i>, QStringRef <i>s2</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#compare">compare</a>().</p>
<h3 class="fn"><a name="contains" />bool QString.contains (<i>self</i>, QString <i>str</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>Returns true if this string contains an occurrence of the string
<i>str</i>; otherwise returns false.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"Peter Pan"</span>;
str<span class="operator">.</span>contains(<span class="string">"peter"</span><span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>CaseInsensitive); <span class="comment">// returns true</span>
</pre>
<p><b>See also</b> <a href="qstring.html#indexOf">indexOf</a>() and
<a href="qstring.html#count">count</a>().</p>
<h3 class="fn"><a name="contains-2" />bool QString.contains (<i>self</i>, QStringRef <i>s</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>Returns true if this string contains an occurrence of the string
reference <i>str</i>; otherwise returns false.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also</b> <a href="qstring.html#indexOf">indexOf</a>() and
<a href="qstring.html#count">count</a>().</p>
<h3 class="fn"><a name="contains-3" />bool QString.contains (<i>self</i>, <a href="qregexp.html">QRegExp</a> <i>rx</i>)</h3><h3 class="fn"><a name="count" />int QString.count (<i>self</i>)</h3><p>Returns the number of (potentially overlapping) occurrences of
the string <i>str</i> in this string.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p><b>See also</b> <a href="qstring.html#contains">contains</a>()
and <a href="qstring.html#indexOf">indexOf</a>().</p>
<h3 class="fn"><a name="count-2" />int QString.count (<i>self</i>, QString <i>str</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#count">count</a>().</p>
<p>Returns the number of occurrences of character <i>ch</i> in the
string.</p>
<h3 class="fn"><a name="count-3" />int QString.count (<i>self</i>, QStringRef <i>str</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#count">count</a>().</p>
<p>Returns the number of (potentially overlapping) occurrences of
the string reference <i>str</i> in this string.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also</b> <a href="qstring.html#contains">contains</a>()
and <a href="qstring.html#indexOf">indexOf</a>().</p>
<h3 class="fn"><a name="count-4" />int QString.count (<i>self</i>, <a href="qregexp.html">QRegExp</a>)</h3><p>This function overloads <a href="qstring.html#count">count</a>().</p>
<p>Returns the number of times the regular expression <i>rx</i>
matches in the string.</p>
<p>This function counts overlapping matches, so in the example
below, there are four instances of "ana" or "ama":</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"banana and panama"</span>;
str<span class="operator">.</span>count(<span class="type"><a href="qregexp.html">QRegExp</a></span>(<span class="string">"a[nm]a"</span>)); <span class="comment">// returns 4</span>
</pre>
<h3 class="fn"><a name="endsWith" />bool QString.endsWith (<i>self</i>, QString <i>s</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>Returns true if the string ends with <i>s</i>; otherwise returns
false.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"Bananas"</span>;
str<span class="operator">.</span>endsWith(<span class="string">"anas"</span>); <span class="comment">// returns true</span>
str<span class="operator">.</span>endsWith(<span class="string">"pple"</span>); <span class="comment">// returns false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#startsWith">startsWith</a>().</p>
<h3 class="fn"><a name="endsWith-2" />bool QString.endsWith (<i>self</i>, QStringRef <i>s</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><h3 class="fn"><a name="endsWith-3" />bool QString.endsWith (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#endsWith">endsWith</a>().</p>
<p>Returns true if the string ends with the string reference
<i>s</i>; otherwise returns false.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also</b> <a href="qstring.html#startsWith">startsWith</a>().</p>
<h3 class="fn"><a name="fill" />QString QString.fill (<i>self</i>, QChar <i>ch</i>, int <i>size</i> = -1)</h3><p>Sets every character in the string to character <i>ch</i>. If
<i>size</i> is different from -1 (default), the string is resized
to <i>size</i> beforehand.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"Berlin"</span>;
str<span class="operator">.</span>fill(<span class="char">'z'</span>);
<span class="comment">// str == "zzzzzz"</span>
str<span class="operator">.</span>fill(<span class="char">'A'</span><span class="operator">,</span> <span class="number">2</span>);
<span class="comment">// str == "AA"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#resize">resize</a>().</p>
<h3 class="fn"><a name="fromAscii" />QString QString.fromAscii (str <i>str</i>, int <i>size</i> = -1)</h3><p>Returns a <a href="qstring.html">QString</a> initialized with
the first <i>size</i> characters from the string <i>str</i>.</p>
<p>If <i>size</i> is -1 (default), it is taken to be
qstrlen(<i>str</i>).</p>
<p>Note that, despite the name, this function actually uses the
codec defined by <a href="qtextcodec.html#setCodecForCStrings">QTextCodec.setCodecForCStrings</a>()
to convert <i>str</i> to Unicode. Depending on the codec, it may
not accept valid US-ASCII (ANSI X3.4-1986) input. If no codec has
been set, this function does the same as <a href="qstring.html#fromLatin1">fromLatin1</a>().</p>
<p><b>See also</b> <a href="qstring.html#toAscii">toAscii</a>(),
<a href="qstring.html#fromLatin1">fromLatin1</a>(), <a href="qstring.html#fromUtf8">fromUtf8</a>(), and <a href="qstring.html#fromLocal8Bit">fromLocal8Bit</a>().</p>
<h3 class="fn"><a name="fromLatin1" />QString QString.fromLatin1 (str <i>str</i>, int <i>size</i> = -1)</h3><p>Returns a <a href="qstring.html">QString</a> initialized with
the first <i>size</i> characters of the Latin-1 string
<i>str</i>.</p>
<p>If <i>size</i> is -1 (default), it is taken to be
qstrlen(<i>str</i>).</p>
<p><b>See also</b> <a href="qstring.html#toLatin1">toLatin1</a>(),
<a href="qstring.html#fromAscii">fromAscii</a>(), <a href="qstring.html#fromUtf8">fromUtf8</a>(), and <a href="qstring.html#fromLocal8Bit">fromLocal8Bit</a>().</p>
<h3 class="fn"><a name="fromLocal8Bit" />QString QString.fromLocal8Bit (str <i>str</i>, int <i>size</i> = -1)</h3><p>Returns a <a href="qstring.html">QString</a> initialized with
the first <i>size</i> characters of the 8-bit string
<i>str</i>.</p>
<p>If <i>size</i> is -1 (default), it is taken to be
qstrlen(<i>str</i>).</p>
<p><a href="qtextcodec.html#codecForLocale">QTextCodec.codecForLocale</a>()
is used to perform the conversion.</p>
<p><b>See also</b> <a href="qstring.html#toLocal8Bit">toLocal8Bit</a>(), <a href="qstring.html#fromAscii">fromAscii</a>(), <a href="qstring.html#fromLatin1">fromLatin1</a>(), and <a href="qstring.html#fromUtf8">fromUtf8</a>().</p>
<h3 class="fn"><a name="fromUtf8" />QString QString.fromUtf8 (str <i>str</i>, int <i>size</i> = -1)</h3><p>Returns a <a href="qstring.html">QString</a> initialized with
the first <i>size</i> bytes of the UTF-8 string <i>str</i>.</p>
<p>If <i>size</i> is -1 (default), it is taken to be
qstrlen(<i>str</i>).</p>
<p>UTF-8 is a Unicode codec and can represent all characters in a
Unicode string like <a href="qstring.html">QString</a>. However,
invalid sequences are possible with UTF-8 and, if any such are
found, they will be replaced with one or more "replacement
characters", or suppressed. These include non-Unicode sequences,
non-characters, overlong sequences or surrogate codepoints encoded
into UTF-8.</p>
<p>Non-characters are codepoints that the Unicode standard reserves
and must not be used in text interchange. They are the last two
codepoints in each Unicode Plane (U+FFFE, U+FFFF, U+1FFFE, U+1FFFF,
U+2FFFE, etc.), as well as 16 codepoints in the range
U+FDD0..U+FDDF, inclusive.</p>
<p><b>See also</b> <a href="qstring.html#toUtf8">toUtf8</a>(),
<a href="qstring.html#fromAscii">fromAscii</a>(), <a href="qstring.html#fromLatin1">fromLatin1</a>(), and <a href="qstring.html#fromLocal8Bit">fromLocal8Bit</a>().</p>
<h3 class="fn"><a name="indexOf" />int QString.indexOf (<i>self</i>, QString <i>str</i>, int <i>from</i> = 0, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>Returns the index position of the first occurrence of the string
<i>str</i> in this string, searching forward from index position
<i>from</i>. Returns -1 if <i>str</i> is not found.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> x <span class="operator">=</span> <span class="string">"sticky question"</span>;
<span class="type"><a href="qstring.html">QString</a></span> y <span class="operator">=</span> <span class="string">"sti"</span>;
x<span class="operator">.</span>indexOf(y); <span class="comment">// returns 0</span>
x<span class="operator">.</span>indexOf(y<span class="operator">,</span> <span class="number">1</span>); <span class="comment">// returns 10</span>
x<span class="operator">.</span>indexOf(y<span class="operator">,</span> <span class="number">10</span>); <span class="comment">// returns 10</span>
x<span class="operator">.</span>indexOf(y<span class="operator">,</span> <span class="number">11</span>); <span class="comment">// returns -1</span>
</pre>
<p>If <i>from</i> is -1, the search starts at the last character;
if it is -2, at the next to last character and so on.</p>
<p><b>See also</b> <a href="qstring.html#lastIndexOf">lastIndexOf</a>(), <a href="qstring.html#contains">contains</a>(), and <a href="qstring.html#count">count</a>().</p>
<h3 class="fn"><a name="indexOf-2" />int QString.indexOf (<i>self</i>, QStringRef <i>str</i>, int <i>from</i> = 0, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>Returns the index position of the first occurrence of the string
<i>str</i> in this string, searching forward from index position
<i>from</i>. Returns -1 if <i>str</i> is not found.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> x <span class="operator">=</span> <span class="string">"sticky question"</span>;
<span class="type"><a href="qstring.html">QString</a></span> y <span class="operator">=</span> <span class="string">"sti"</span>;
x<span class="operator">.</span>indexOf(y); <span class="comment">// returns 0</span>
x<span class="operator">.</span>indexOf(y<span class="operator">,</span> <span class="number">1</span>); <span class="comment">// returns 10</span>
x<span class="operator">.</span>indexOf(y<span class="operator">,</span> <span class="number">10</span>); <span class="comment">// returns 10</span>
x<span class="operator">.</span>indexOf(y<span class="operator">,</span> <span class="number">11</span>); <span class="comment">// returns -1</span>
</pre>
<p>If <i>from</i> is -1, the search starts at the last character;
if it is -2, at the next to last character and so on.</p>
<p>This function was introduced in Qt 4.5.</p>
<p><b>See also</b> <a href="qstring.html#lastIndexOf">lastIndexOf</a>(), <a href="qstring.html#contains">contains</a>(), and <a href="qstring.html#count">count</a>().</p>
<h3 class="fn"><a name="indexOf-3" />int QString.indexOf (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>str</i>, int <i>from</i> = 0, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#indexOf">indexOf</a>().</p>
<p>Returns the index position of the first occurrence of the
character <i>ch</i> in the string, searching forward from index
position <i>from</i>. Returns -1 if <i>ch</i> could not be
found.</p>
<h3 class="fn"><a name="indexOf-4" />int QString.indexOf (<i>self</i>, <a href="qregexp.html">QRegExp</a> <i>rx</i>, int <i>from</i> = 0)</h3><p>This function overloads <a href="qstring.html#indexOf">indexOf</a>().</p>
<p>Returns the index position of the first occurrence of the string
reference <i>str</i> in this string, searching forward from index
position <i>from</i>. Returns -1 if <i>str</i> is not found.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>This function was introduced in Qt 4.8.</p>
<h3 class="fn"><a name="insert" />QString QString.insert (<i>self</i>, int <i>i</i>, QString <i>s</i>)</h3><p>Inserts the string <i>str</i> at the given index <i>position</i>
and returns a reference to this string.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"Meal"</span>;
str<span class="operator">.</span>insert(<span class="number">1</span><span class="operator">,</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="string">"ontr"</span>));
<span class="comment">// str == "Montreal"</span>
</pre>
<p>If the given <i>position</i> is greater than <a href="qstring.html#size">size</a>(), the array is first extended using
<a href="qstring.html#resize">resize</a>().</p>
<p><b>See also</b> <a href="qstring.html#append">append</a>(),
<a href="qstring.html#prepend">prepend</a>(), <a href="qstring.html#replace">replace</a>(), and <a href="qstring.html#remove">remove</a>().</p>
<h3 class="fn"><a name="insert-2" />QString QString.insert (<i>self</i>, int <i>i</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>)</h3><p>This function overloads <a href="qstring.html#insert">insert</a>().</p>
<p>Inserts the Latin-1 string <i>str</i> at the given index
<i>position</i>.</p>
<h3 class="fn"><a name="isEmpty" />bool QString.isEmpty (<i>self</i>)</h3><p>Returns true if the string has no characters; otherwise returns
false.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span>()<span class="operator">.</span>isEmpty(); <span class="comment">// returns true</span>
<span class="type"><a href="qstring.html">QString</a></span>(<span class="string">""</span>)<span class="operator">.</span>isEmpty(); <span class="comment">// returns true</span>
<span class="type"><a href="qstring.html">QString</a></span>(<span class="string">"x"</span>)<span class="operator">.</span>isEmpty(); <span class="comment">// returns false</span>
<span class="type"><a href="qstring.html">QString</a></span>(<span class="string">"abc"</span>)<span class="operator">.</span>isEmpty(); <span class="comment">// returns false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#size">size</a>().</p>
<h3 class="fn"><a name="isNull" />bool QString.isNull (<i>self</i>)</h3><p>Returns true if this string is null; otherwise returns
false.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span>()<span class="operator">.</span>isNull(); <span class="comment">// returns true</span>
<span class="type"><a href="qstring.html">QString</a></span>(<span class="string">""</span>)<span class="operator">.</span>isNull(); <span class="comment">// returns false</span>
<span class="type"><a href="qstring.html">QString</a></span>(<span class="string">"abc"</span>)<span class="operator">.</span>isNull(); <span class="comment">// returns false</span>
</pre>
<p>Qt makes a distinction between null strings and empty strings
for historical reasons. For most applications, what matters is
whether or not a string contains any data, and this can be
determined using the <a href="qstring.html#isEmpty">isEmpty</a>()
function.</p>
<p><b>See also</b> <a href="qstring.html#isEmpty">isEmpty</a>().</p>
<h3 class="fn"><a name="isRightToLeft" />bool QString.isRightToLeft (<i>self</i>)</h3><p>Returns true if the string is read right to left.</p>
<h3 class="fn"><a name="isSimpleText" />bool QString.isSimpleText (<i>self</i>)</h3><h3 class="fn"><a name="lastIndexOf" />int QString.lastIndexOf (<i>self</i>, QString <i>str</i>, int <i>from</i> = -1, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>Returns the index position of the last occurrence of the string
<i>str</i> in this string, searching backward from index position
<i>from</i>. If <i>from</i> is -1 (default), the search starts at
the last character; if <i>from</i> is -2, at the next to last
character and so on. Returns -1 if <i>str</i> is not found.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> x <span class="operator">=</span> <span class="string">"crazy azimuths"</span>;
<span class="type"><a href="qstring.html">QString</a></span> y <span class="operator">=</span> <span class="string">"az"</span>;
x<span class="operator">.</span>lastIndexOf(y); <span class="comment">// returns 6</span>
x<span class="operator">.</span>lastIndexOf(y<span class="operator">,</span> <span class="number">6</span>); <span class="comment">// returns 6</span>
x<span class="operator">.</span>lastIndexOf(y<span class="operator">,</span> <span class="number">5</span>); <span class="comment">// returns 2</span>
x<span class="operator">.</span>lastIndexOf(y<span class="operator">,</span> <span class="number">1</span>); <span class="comment">// returns -1</span>
</pre>
<p><b>See also</b> <a href="qstring.html#indexOf">indexOf</a>(),
<a href="qstring.html#contains">contains</a>(), and <a href="qstring.html#count">count</a>().</p>
<h3 class="fn"><a name="lastIndexOf-2" />int QString.lastIndexOf (<i>self</i>, QStringRef <i>str</i>, int <i>from</i> = -1, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#lastIndexOf">lastIndexOf</a>().</p>
<p>Returns the index position of the last occurrence of the string
<i>str</i> in this string, searching backward from index position
<i>from</i>. If <i>from</i> is -1 (default), the search starts at
the last character; if <i>from</i> is -2, at the next to last
character and so on. Returns -1 if <i>str</i> is not found.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> x <span class="operator">=</span> <span class="string">"crazy azimuths"</span>;
<span class="type"><a href="qstring.html">QString</a></span> y <span class="operator">=</span> <span class="string">"az"</span>;
x<span class="operator">.</span>lastIndexOf(y); <span class="comment">// returns 6</span>
x<span class="operator">.</span>lastIndexOf(y<span class="operator">,</span> <span class="number">6</span>); <span class="comment">// returns 6</span>
x<span class="operator">.</span>lastIndexOf(y<span class="operator">,</span> <span class="number">5</span>); <span class="comment">// returns 2</span>
x<span class="operator">.</span>lastIndexOf(y<span class="operator">,</span> <span class="number">1</span>); <span class="comment">// returns -1</span>
</pre>
<p>This function was introduced in Qt 4.5.</p>
<p><b>See also</b> <a href="qstring.html#indexOf">indexOf</a>(),
<a href="qstring.html#contains">contains</a>(), and <a href="qstring.html#count">count</a>().</p>
<h3 class="fn"><a name="lastIndexOf-3" />int QString.lastIndexOf (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>str</i>, int <i>from</i> = -1, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#lastIndexOf">lastIndexOf</a>().</p>
<p>Returns the index position of the last occurrence of the
character <i>ch</i>, searching backward from position
<i>from</i>.</p>
<h3 class="fn"><a name="lastIndexOf-4" />int QString.lastIndexOf (<i>self</i>, <a href="qregexp.html">QRegExp</a> <i>rx</i>, int <i>from</i> = -1)</h3><p>This function overloads <a href="qstring.html#lastIndexOf">lastIndexOf</a>().</p>
<p>Returns the index position of the last occurrence of the string
reference <i>str</i> in this string, searching backward from index
position <i>from</i>. If <i>from</i> is -1 (default), the search
starts at the last character; if <i>from</i> is -2, at the next to
last character and so on. Returns -1 if <i>str</i> is not
found.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also</b> <a href="qstring.html#indexOf">indexOf</a>(),
<a href="qstring.html#contains">contains</a>(), and <a href="qstring.html#count">count</a>().</p>
<h3 class="fn"><a name="left" />QString QString.left (<i>self</i>, int <i>len</i>)</h3><p>Returns a substring that contains the <i>n</i> leftmost
characters of the string.</p>
<p>The entire string is returned if <i>n</i> is greater than
<a href="qstring.html#size">size</a>() or less than zero.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> x <span class="operator">=</span> <span class="string">"Pineapple"</span>;
<span class="type"><a href="qstring.html">QString</a></span> y <span class="operator">=</span> x<span class="operator">.</span>left(<span class="number">4</span>); <span class="comment">// y == "Pine"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#right">right</a>(),
<a href="qstring.html#mid">mid</a>(), and <a href="qstring.html#startsWith">startsWith</a>().</p>
<h3 class="fn"><a name="leftJustified" />QString QString.leftJustified (<i>self</i>, int <i>width</i>, QChar <i>fillChar</i> = QLatin1Char(' '), bool <i>truncate</i> = False)</h3><p>Returns a string of size <i>width</i> that contains this string
padded by the <i>fill</i> character.</p>
<p>If <i>truncate</i> is false and the <a href="qstring.html#size">size</a>() of the string is more than
<i>width</i>, then the returned string is a copy of the string.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> s <span class="operator">=</span> <span class="string">"apple"</span>;
<span class="type"><a href="qstring.html">QString</a></span> t <span class="operator">=</span> s<span class="operator">.</span>leftJustified(<span class="number">8</span><span class="operator">,</span> <span class="char">'.'</span>); <span class="comment">// t == "apple..."</span>
</pre>
<p>If <i>truncate</i> is true and the <a href="qstring.html#size">size</a>() of the string is more than
<i>width</i>, then any characters in a copy of the string after
position <i>width</i> are removed, and the copy is returned.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"Pineapple"</span>;
str <span class="operator">=</span> str<span class="operator">.</span>leftJustified(<span class="number">5</span><span class="operator">,</span> <span class="char">'.'</span><span class="operator">,</span> <span class="keyword">true</span>); <span class="comment">// str == "Pinea"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#rightJustified">rightJustified</a>().</p>
<h3 class="fn"><a name="length" />int QString.length (<i>self</i>)</h3><p>Returns the number of characters in this string. Equivalent to
<a href="qstring.html#size">size</a>().</p>
<p><b>See also</b> <a class="compat" href="qstring-qt3.html#setLength">setLength</a>() and <a href="qstring.html#resize">resize</a>().</p>
<h3 class="fn"><a name="localeAwareCompare" />int QString.localeAwareCompare (<i>self</i>, QString <i>s</i>)</h3><p>Compares <i>s1</i> with <i>s2</i> and returns an integer less
than, equal to, or greater than zero if <i>s1</i> is less than,
equal to, or greater than <i>s2</i>.</p>
<p>The comparison is performed in a locale- and also
platform-dependent manner. Use this function to present sorted
lists of strings to the user.</p>
<p>On Mac OS X since Qt 4.3, this function compares according the
"Order for sorted lists" setting in the International prefereces
panel.</p>
<p><b>See also</b> <a href="qstring.html#compare">compare</a>() and
<a class="compat" href="qtextcodec-qt3.html#locale">QTextCodec.locale</a>().</p>
<h3 class="fn"><a name="localeAwareCompare-2" />int QString.localeAwareCompare (<i>self</i>, QStringRef <i>s</i>)</h3><p>This function overloads <a href="qstring.html#localeAwareCompare">localeAwareCompare</a>().</p>
<p>Compares this string with the <i>other</i> string and returns an
integer less than, equal to, or greater than zero if this string is
less than, equal to, or greater than the <i>other</i> string.</p>
<p>The comparison is performed in a locale- and also
platform-dependent manner. Use this function to present sorted
lists of strings to the user.</p>
<p>Same as <tt>localeAwareCompare(*this, other)</tt>.</p>
<p>This function was introduced in Qt 4.5.</p>
<h3 class="fn"><a name="localeAwareCompare-3" />int QString.localeAwareCompare (QString <i>s1</i>, QString <i>s2</i>)</h3><p>This function overloads <a href="qstring.html#localeAwareCompare">localeAwareCompare</a>().</p>
<p>Compares <i>s1</i> with <i>s2</i> and returns an integer less
than, equal to, or greater than zero if <i>s1</i> is less than,
equal to, or greater than <i>s2</i>.</p>
<p>The comparison is performed in a locale- and also
platform-dependent manner. Use this function to present sorted
lists of strings to the user.</p>
<p>This function was introduced in Qt 4.5.</p>
<h3 class="fn"><a name="localeAwareCompare-4" />int QString.localeAwareCompare (QString <i>s1</i>, QStringRef <i>s2</i>)</h3><p>This function overloads <a href="qstring.html#localeAwareCompare">localeAwareCompare</a>().</p>
<p>Compares this string with the <i>other</i> string and returns an
integer less than, equal to, or greater than zero if this string is
less than, equal to, or greater than the <i>other</i> string.</p>
<p>The comparison is performed in a locale- and also
platform-dependent manner. Use this function to present sorted
lists of strings to the user.</p>
<p>Same as <tt>localeAwareCompare(*this, other)</tt>.</p>
<h3 class="fn"><a name="mid" />QString QString.mid (<i>self</i>, int <i>position</i>, int <i>n</i> = -1)</h3><p>Returns a string that contains <i>n</i> characters of this
string, starting at the specified <i>position</i> index.</p>
<p>Returns a null string if the <i>position</i> index exceeds the
length of the string. If there are less than <i>n</i> characters
available in the string starting at the given <i>position</i>, or
if <i>n</i> is -1 (default), the function returns all characters
that are available from the specified <i>position</i>.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> x <span class="operator">=</span> <span class="string">"Nine pineapples"</span>;
<span class="type"><a href="qstring.html">QString</a></span> y <span class="operator">=</span> x<span class="operator">.</span>mid(<span class="number">5</span><span class="operator">,</span> <span class="number">4</span>); <span class="comment">// y == "pine"</span>
<span class="type"><a href="qstring.html">QString</a></span> z <span class="operator">=</span> x<span class="operator">.</span>mid(<span class="number">5</span>); <span class="comment">// z == "pineapples"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#left">left</a>() and
<a href="qstring.html#right">right</a>().</p>
<h3 class="fn"><a name="normalized" />QString QString.normalized (<i>self</i>, <a href="qstring.html#NormalizationForm-enum">NormalizationForm</a> <i>mode</i>)</h3><p>Returns the string in the given Unicode normalization
<i>mode</i>.</p>
<h3 class="fn"><a name="normalized-2" />QString QString.normalized (<i>self</i>, <a href="qstring.html#NormalizationForm-enum">NormalizationForm</a> <i>mode</i>, <a href="qchar.html#UnicodeVersion-enum">QChar.UnicodeVersion</a> <i>version</i>)</h3><p>This is an overloaded function.</p>
<p>Returns the string in the given Unicode normalization
<i>mode</i>, according to the given <i>version</i> of the Unicode
standard.</p>
<h3 class="fn"><a name="number" />QString QString.number (int <i>n</i>, int <i>base</i> = 10)</h3><p>Returns a string equivalent of the number <i>n</i> according to
the specified <i>base</i>.</p>
<p>The base is 10 by default and must be between 2 and 36. For
bases other than 10, <i>n</i> is treated as an unsigned
integer.</p>
<pre class="cpp">
<span class="type">long</span> a <span class="operator">=</span> <span class="number">63</span>;
<span class="type"><a href="qstring.html">QString</a></span> s <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span><span class="operator">.</span>number(a<span class="operator">,</span> <span class="number">16</span>); <span class="comment">// s == "3f"</span>
<span class="type"><a href="qstring.html">QString</a></span> t <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span><span class="operator">.</span>number(a<span class="operator">,</span> <span class="number">16</span>)<span class="operator">.</span>toUpper(); <span class="comment">// t == "3F"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#setNum">setNum</a>().</p>
<h3 class="fn"><a name="number-2" />QString QString.number (float <i>n</i>, str <i>format</i> = 'g', int <i>precision</i> = 6)</h3><p>Returns a string equivalent of the number <i>n</i>, formatted
according to the specified <i>format</i> and <i>precision</i>. See
<a href="qstring.html#argument-formats">Argument Formats</a> for
details.</p>
<p>Unlike <a href="qlocale.html#toString">QLocale.toString</a>(),
this function does not honor the user's locale settings.</p>
<p><b>See also</b> <a href="qstring.html#setNum">setNum</a>() and
<a href="qlocale.html#toString">QLocale.toString</a>().</p>
<h3 class="fn"><a name="number-3" />QString QString.number (int <i>n</i>, int <i>base</i> = 10)</h3><p>This is an overloaded function.</p>
<h3 class="fn"><a name="number-4" />QString QString.number (int <i>n</i>, int <i>base</i> = 10)</h3><p>This is an overloaded function.</p>
<h3 class="fn"><a name="prepend" />QString QString.prepend (<i>self</i>, QString <i>s</i>)</h3><p>Prepends the string <i>str</i> to the beginning of this string
and returns a reference to this string.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> x <span class="operator">=</span> <span class="string">"ship"</span>;
<span class="type"><a href="qstring.html">QString</a></span> y <span class="operator">=</span> <span class="string">"air"</span>;
x<span class="operator">.</span>prepend(y);
<span class="comment">// x == "airship"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#append">append</a>() and
<a href="qstring.html#insert">insert</a>().</p>
<h3 class="fn"><a name="prepend-2" />QString QString.prepend (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>)</h3><p>This function overloads <a href="qstring.html#prepend">prepend</a>().</p>
<p>Prepends the Latin-1 string <i>str</i> to this string.</p>
<h3 class="fn"><a name="prepend-3" />QString QString.prepend (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>s</i>)</h3><p>This function overloads <a href="qstring.html#prepend">prepend</a>().</p>
<p>Prepends the byte array <i>ba</i> to this string. The byte array
is converted to Unicode using the <a href="qstring.html#fromAscii">fromAscii</a>() function.</p>
<p>You can disable this function by defining
<tt>QT_NO_CAST_FROM_ASCII</tt> when you compile your applications.
This can be useful if you want to ensure that all user-visible
strings go through <a href="qobject.html#tr">QObject.tr</a>(), for
example.</p>
<h3 class="fn"><a name="push_back" />QString.push_back (<i>self</i>, QString <i>s</i>)</h3><p>This function is provided for STL compatibility, appending the
given <i>other</i> string onto the end of this string. It is
equivalent to <tt>append(other)</tt>.</p>
<p><b>See also</b> <a href="qstring.html#append">append</a>().</p>
<h3 class="fn"><a name="push_front" />QString.push_front (<i>self</i>, QString <i>s</i>)</h3><p>This function is provided for STL compatibility, prepending the
given <i>other</i> string to the beginning of this string. It is
equivalent to <tt>prepend(other)</tt>.</p>
<p><b>See also</b> <a href="qstring.html#prepend">prepend</a>().</p>
<h3 class="fn"><a name="remove" />QString QString.remove (<i>self</i>, int <i>i</i>, int <i>len</i>)</h3><p>Removes <i>n</i> characters from the string, starting at the
given <i>position</i> index, and returns a reference to the
string.</p>
<p>If the specified <i>position</i> index is within the string, but
<i>position</i> + <i>n</i> is beyond the end of the string, the
string is truncated at the specified <i>position</i>.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> s <span class="operator">=</span> <span class="string">"Montreal"</span>;
s<span class="operator">.</span>remove(<span class="number">1</span><span class="operator">,</span> <span class="number">4</span>);
<span class="comment">// s == "Meal"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#insert">insert</a>() and
<a href="qstring.html#replace">replace</a>().</p>
<h3 class="fn"><a name="remove-2" />QString QString.remove (<i>self</i>, QString <i>str</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>Removes every occurrence of the character <i>ch</i> in this
string, and returns a reference to this string.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> t <span class="operator">=</span> <span class="string">"Ali Baba"</span>;
t<span class="operator">.</span>remove(<span class="type"><a href="qchar.html">QChar</a></span>(<span class="char">'a'</span>)<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>CaseInsensitive);
<span class="comment">// t == "li Bb"</span>
</pre>
<p>This is the same as <tt>replace(ch, "", cs)</tt>.</p>
<p><b>See also</b> <a href="qstring.html#replace">replace</a>().</p>
<h3 class="fn"><a name="remove-3" />QString QString.remove (<i>self</i>, <a href="qregexp.html">QRegExp</a> <i>rx</i>)</h3><p>Removes every occurrence of the given <i>str</i> string in this
string, and returns a reference to this string.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<p>This is the same as <tt>replace(str, "", cs)</tt>.</p>
<p><b>See also</b> <a href="qstring.html#replace">replace</a>().</p>
<h3 class="fn"><a name="repeated" />QString QString.repeated (<i>self</i>, int <i>times</i>)</h3><p>Returns a copy of this string repeated the specified number of
<i>times</i>.</p>
<p>If <i>times</i> is less than 1, an empty string is returned.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str(<span class="string">"ab"</span>);
str<span class="operator">.</span>repeated(<span class="number">4</span>); <span class="comment">// returns "abababab"</span>
</pre>
<p>This function was introduced in Qt 4.5.</p>
<h3 class="fn"><a name="replace" />QString QString.replace (<i>self</i>, int <i>i</i>, int <i>len</i>, QString <i>after</i>)</h3><p>Replaces <i>n</i> characters beginning at index <i>position</i>
with the string <i>after</i> and returns a reference to this
string.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> x <span class="operator">=</span> <span class="string">"Say yes!"</span>;
<span class="type"><a href="qstring.html">QString</a></span> y <span class="operator">=</span> <span class="string">"no"</span>;
x<span class="operator">.</span>replace(<span class="number">4</span><span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> y);
<span class="comment">// x == "Say no!"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#insert">insert</a>() and
<a href="qstring.html#remove">remove</a>().</p>
<h3 class="fn"><a name="replace-2" />QString QString.replace (<i>self</i>, QString <i>before</i>, QString <i>after</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><h3 class="fn"><a name="replace-3" />QString QString.replace (<i>self</i>, <a href="qregexp.html">QRegExp</a> <i>rx</i>, QString <i>after</i>)</h3><h3 class="fn"><a name="replace-4" />QString QString.replace (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>before</i>, <a href="qlatin1string.html">QLatin1String</a> <i>after</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><h3 class="fn"><a name="replace-5" />QString QString.replace (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>before</i>, QString <i>after</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><h3 class="fn"><a name="replace-6" />QString QString.replace (<i>self</i>, QString <i>before</i>, <a href="qlatin1string.html">QLatin1String</a> <i>after</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#replace">replace</a>().</p>
<p>Replaces <i>n</i> characters beginning at index <i>position</i>
with the first <i>size</i> characters of the <a href="qchar.html">QChar</a> array <i>unicode</i> and returns a reference
to this string.</p>
<h3 class="fn"><a name="reserve" />QString.reserve (<i>self</i>, int <i>asize</i>)</h3><p>Attempts to allocate memory for at least <i>size</i> characters.
If you know in advance how large the string will be, you can call
this function, and if you resize the string often you are likely to
get better performance. If <i>size</i> is an underestimate, the
worst that will happen is that the <a href="qstring.html">QString</a> will be a bit slower.</p>
<p>The sole purpose of this function is to provide a means of fine
tuning <a href="qstring.html">QString</a>'s memory usage. In
general, you will rarely ever need to call this function. If you
want to change the size of the string, call <a href="qstring.html#resize">resize</a>().</p>
<p>This function is useful for code that needs to build up a long
string and wants to avoid repeated reallocation. In this example,
we want to add to the string until some condition is true, and
we're fairly sure that size is large enough to make a call to
reserve() worthwhile:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> result;
<span class="type">int</span> maxSize;
<span class="type">bool</span> condition;
<span class="type"><a href="qchar.html">QChar</a></span> nextChar;
result<span class="operator">.</span>reserve(maxSize);
<span class="keyword">while</span> (condition)
result<span class="operator">.</span>append(nextChar);
result<span class="operator">.</span>squeeze();
</pre>
<p><b>See also</b> <a href="qstring.html#squeeze">squeeze</a>() and
<a href="qstring.html#capacity">capacity</a>().</p>
<h3 class="fn"><a name="resize" />QString.resize (<i>self</i>, int <i>size</i>)</h3><p>Sets the size of the string to <i>size</i> characters.</p>
<p>If <i>size</i> is greater than the current size, the string is
extended to make it <i>size</i> characters long with the extra
characters added to the end. The new characters are
uninitialized.</p>
<p>If <i>size</i> is less than the current size, characters are
removed from the end.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> s <span class="operator">=</span> <span class="string">"Hello world"</span>;
s<span class="operator">.</span>resize(<span class="number">5</span>);
<span class="comment">// s == "Hello"</span>
s<span class="operator">.</span>resize(<span class="number">8</span>);
<span class="comment">// s == "Hello???" (where ? stands for any character)</span>
</pre>
<p>If you want to append a certain number of identical characters
to the string, use <a href="qstring.html#operator-2b-eq">operator+=</a>() as follows rather
than resize():</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> t <span class="operator">=</span> <span class="string">"Hello"</span>;
t <span class="operator">+</span><span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="number">10</span><span class="operator">,</span> <span class="char">'X'</span>);
<span class="comment">// t == "HelloXXXXXXXXXX"</span>
</pre>
<p>If you want to expand the string so that it reaches a certain
width and fill the new positions with a particular character, use
the <a href="qstring.html#leftJustified">leftJustified</a>()
function:</p>
<p>If <i>size</i> is negative, it is equivalent to passing
zero.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> r <span class="operator">=</span> <span class="string">"Hello"</span>;
r <span class="operator">=</span> r<span class="operator">.</span>leftJustified(<span class="number">10</span><span class="operator">,</span> <span class="char">' '</span>);
<span class="comment">// r == "Hello "</span>
</pre>
<p><b>See also</b> <a href="qstring.html#truncate">truncate</a>()
and <a href="qstring.html#reserve">reserve</a>().</p>
<h3 class="fn"><a name="right" />QString QString.right (<i>self</i>, int <i>len</i>)</h3><p>Returns a substring that contains the <i>n</i> rightmost
characters of the string.</p>
<p>The entire string is returned if <i>n</i> is greater than
<a href="qstring.html#size">size</a>() or less than zero.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> x <span class="operator">=</span> <span class="string">"Pineapple"</span>;
<span class="type"><a href="qstring.html">QString</a></span> y <span class="operator">=</span> x<span class="operator">.</span>right(<span class="number">5</span>); <span class="comment">// y == "apple"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#left">left</a>(), <a href="qstring.html#mid">mid</a>(), and <a href="qstring.html#endsWith">endsWith</a>().</p>
<h3 class="fn"><a name="rightJustified" />QString QString.rightJustified (<i>self</i>, int <i>width</i>, QChar <i>fillChar</i> = QLatin1Char(' '), bool <i>truncate</i> = False)</h3><p>Returns a string of <a href="qstring.html#size">size</a>()
<i>width</i> that contains the <i>fill</i> character followed by
the string. For example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> s <span class="operator">=</span> <span class="string">"apple"</span>;
<span class="type"><a href="qstring.html">QString</a></span> t <span class="operator">=</span> s<span class="operator">.</span>rightJustified(<span class="number">8</span><span class="operator">,</span> <span class="char">'.'</span>); <span class="comment">// t == "...apple"</span>
</pre>
<p>If <i>truncate</i> is false and the <a href="qstring.html#size">size</a>() of the string is more than
<i>width</i>, then the returned string is a copy of the string.</p>
<p>If <i>truncate</i> is true and the <a href="qstring.html#size">size</a>() of the string is more than
<i>width</i>, then the resulting string is truncated at position
<i>width</i>.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"Pineapple"</span>;
str <span class="operator">=</span> str<span class="operator">.</span>rightJustified(<span class="number">5</span><span class="operator">,</span> <span class="char">'.'</span><span class="operator">,</span> <span class="keyword">true</span>); <span class="comment">// str == "Pinea"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#leftJustified">leftJustified</a>().</p>
<h3 class="fn"><a name="section" />QString QString.section (<i>self</i>, QString <i>sep</i>, int <i>start</i>, int <i>end</i> = -1, <a href="qstring-sectionflags.html">SectionFlags</a> <i>flags</i> = QString.SectionDefault)</h3><p>This function returns a section of the string.</p>
<p>This string is treated as a sequence of fields separated by the
character, <i>sep</i>. The returned string consists of the fields
from position <i>start</i> to position <i>end</i> inclusive. If
<i>end</i> is not specified, all fields from position <i>start</i>
to the end of the string are included. Fields are numbered 0, 1, 2,
etc., counting from the left, and -1, -2, etc., counting from right
to left.</p>
<p>The <i>flags</i> argument can be used to affect some aspects of
the function's behavior, e.g. whether to be case sensitive, whether
to skip empty fields and how to deal with leading and trailing
separators; see <a href="qstring.html#SectionFlag-enum">SectionFlags</a>.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str;
<span class="type"><a href="qstring.html">QString</a></span> csv <span class="operator">=</span> <span class="string">"forename,middlename,surname,phone"</span>;
<span class="type"><a href="qstring.html">QString</a></span> path <span class="operator">=</span> <span class="string">"/usr/local/bin/myapp"</span>; <span class="comment">// First field is empty</span>
<span class="type"><a href="qstring.html">QString</a></span><span class="operator">.</span>SectionFlag flag <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span><span class="operator">.</span>SectionSkipEmpty;
str <span class="operator">=</span> csv<span class="operator">.</span>section(<span class="char">','</span><span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">2</span>); <span class="comment">// str == "surname"</span>
str <span class="operator">=</span> path<span class="operator">.</span>section(<span class="char">'/'</span><span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">4</span>); <span class="comment">// str == "bin/myapp"</span>
str <span class="operator">=</span> path<span class="operator">.</span>section(<span class="char">'/'</span><span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> flag); <span class="comment">// str == "myapp"</span>
</pre>
<p>If <i>start</i> or <i>end</i> is negative, we count fields from
the right of the string, the right-most field being -1, the one
from right-most field being -2, and so on.</p>
<pre class="cpp">
str <span class="operator">=</span> csv<span class="operator">.</span>section(<span class="char">','</span><span class="operator">,</span> <span class="operator">-</span><span class="number">3</span><span class="operator">,</span> <span class="operator">-</span><span class="number">2</span>); <span class="comment">// str == "middlename,surname"</span>
str <span class="operator">=</span> path<span class="operator">.</span>section(<span class="char">'/'</span><span class="operator">,</span> <span class="operator">-</span><span class="number">1</span>); <span class="comment">// str == "myapp"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#split">split</a>().</p>
<h3 class="fn"><a name="section-2" />QString QString.section (<i>self</i>, <a href="qregexp.html">QRegExp</a> <i>reg</i>, int <i>start</i>, int <i>end</i> = -1, <a href="qstring-sectionflags.html">SectionFlags</a> <i>flags</i> = QString.SectionDefault)</h3><p>This function overloads <a href="qstring.html#section">section</a>().</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str;
<span class="type"><a href="qstring.html">QString</a></span> data <span class="operator">=</span> <span class="string">"forename**middlename**surname**phone"</span>;
str <span class="operator">=</span> data<span class="operator">.</span>section(<span class="string">"**"</span><span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">2</span>); <span class="comment">// str == "surname"</span>
str <span class="operator">=</span> data<span class="operator">.</span>section(<span class="string">"**"</span><span class="operator">,</span> <span class="operator">-</span><span class="number">3</span><span class="operator">,</span> <span class="operator">-</span><span class="number">2</span>); <span class="comment">// str == "middlename**surname"</span>
</pre>
<p><b>See also</b> <a href="qstring.html#split">split</a>().</p>
<h3 class="fn"><a name="setNum" />QString QString.setNum (<i>self</i>, int <i>n</i>, int <i>base</i> = 10)</h3><p>Sets the string to the printed value of <i>n</i> in the
specified <i>base</i>, and returns a reference to the string.</p>
<p>The base is 10 by default and must be between 2 and 36. For
bases other than 10, <i>n</i> is treated as an unsigned
integer.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str;
str<span class="operator">.</span>setNum(<span class="number">1234</span>); <span class="comment">// str == "1234"</span>
</pre>
<p>The formatting always uses <a href="qlocale.html#Language-enum">QLocale.C</a>, i.e.,
English/UnitedStates. To get a localized string representation of a
number, use <a href="qlocale.html#toString">QLocale.toString</a>()
with the appropriate locale.</p>
<h3 class="fn"><a name="setNum-2" />QString QString.setNum (<i>self</i>, float <i>n</i>, str <i>format</i> = 'g', int <i>precision</i> = 6)</h3><p>This is an overloaded function.</p>
<h3 class="fn"><a name="setNum-3" />QString QString.setNum (<i>self</i>, int <i>n</i>, int <i>base</i> = 10)</h3><p>This is an overloaded function.</p>
<h3 class="fn"><a name="setNum-4" />QString QString.setNum (<i>self</i>, int <i>n</i>, int <i>base</i> = 10)</h3><p>This is an overloaded function.</p>
<h3 class="fn"><a name="simplified" />QString QString.simplified (<i>self</i>)</h3><p>Returns a string that has whitespace removed from the start and
the end, and that has each sequence of internal whitespace replaced
with a single space.</p>
<p>Whitespace means any character for which <a href="qchar.html#isSpace">QChar.isSpace</a>() returns true. This
includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and '
'.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">" lots\t of\nwhitespace\r\n "</span>;
str <span class="operator">=</span> str<span class="operator">.</span>simplified();
<span class="comment">// str == "lots of whitespace";</span>
</pre>
<p><b>See also</b> <a href="qstring.html#trimmed">trimmed</a>().</p>
<h3 class="fn"><a name="size" />int QString.size (<i>self</i>)</h3><p>Returns the number of characters in this string.</p>
<p>The last character in the string is at position size() - 1. In
addition, <a href="qstring.html">QString</a> ensures that the
character at position size() is always '\0', so that you can use
the return value of <a href="qstring.html#data">data</a>() and
<a href="qstring.html#constData">constData</a>() as arguments to
functions that expect '\0'-terminated strings.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"World"</span>;
<span class="type">int</span> n <span class="operator">=</span> str<span class="operator">.</span>size(); <span class="comment">// n == 5</span>
str<span class="operator">.</span>data()<span class="operator">[</span><span class="number">0</span><span class="operator">]</span>; <span class="comment">// returns 'W'</span>
str<span class="operator">.</span>data()<span class="operator">[</span><span class="number">4</span><span class="operator">]</span>; <span class="comment">// returns 'd'</span>
str<span class="operator">.</span>data()<span class="operator">[</span><span class="number">5</span><span class="operator">]</span>; <span class="comment">// returns '\0'</span>
</pre>
<p><b>See also</b> <a href="qstring.html#isEmpty">isEmpty</a>() and
<a href="qstring.html#resize">resize</a>().</p>
<h3 class="fn"><a name="split" />QStringList QString.split (<i>self</i>, QString <i>sep</i>, <a href="qstring.html#SplitBehavior-enum">SplitBehavior</a> <i>behavior</i> = QString.KeepEmptyParts, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>Splits the string into substrings wherever <i>sep</i> occurs,
and returns the list of those strings. If <i>sep</i> does not match
anywhere in the string, split() returns a single-element list
containing this string.</p>
<p><i>cs</i> specifies whether <i>sep</i> should be matched case
sensitively or case insensitively.</p>
<p>If <i>behavior</i> is <a href="qstring.html#SplitBehavior-enum">QString.SkipEmptyParts</a>,
empty entries don't appear in the result. By default, empty entries
are kept.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"a,,b,c"</span>;
<span class="type"><a href="qstringlist.html">QStringList</a></span> list1 <span class="operator">=</span> str<span class="operator">.</span>split(<span class="string">","</span>);
<span class="comment">// list1: [ "a", "", "b", "c" ]</span>
<span class="type"><a href="qstringlist.html">QStringList</a></span> list2 <span class="operator">=</span> str<span class="operator">.</span>split(<span class="string">","</span><span class="operator">,</span> <span class="type"><a href="qstring.html">QString</a></span><span class="operator">.</span>SkipEmptyParts);
<span class="comment">// list2: [ "a", "b", "c" ]</span>
</pre>
<p><b>See also</b> <a href="qstringlist.html#join">QStringList.join</a>() and <a href="qstring.html#section">section</a>().</p>
<h3 class="fn"><a name="split-2" />QStringList QString.split (<i>self</i>, <a href="qregexp.html">QRegExp</a> <i>sep</i>, <a href="qstring.html#SplitBehavior-enum">SplitBehavior</a> <i>behavior</i> = QString.KeepEmptyParts)</h3><p>This is an overloaded function.</p>
<h3 class="fn"><a name="squeeze" />QString.squeeze (<i>self</i>)</h3><p>Releases any memory not required to store the character
data.</p>
<p>The sole purpose of this function is to provide a means of fine
tuning <a href="qstring.html">QString</a>'s memory usage. In
general, you will rarely ever need to call this function.</p>
<p><b>See also</b> <a href="qstring.html#reserve">reserve</a>() and
<a href="qstring.html#capacity">capacity</a>().</p>
<h3 class="fn"><a name="startsWith" />bool QString.startsWith (<i>self</i>, QString <i>s</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>Returns true if the string starts with <i>s</i>; otherwise
returns false.</p>
<p>If <i>cs</i> is <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitive</a> (default), the
search is case sensitive; otherwise the search is case
insensitive.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"Bananas"</span>;
str<span class="operator">.</span>startsWith(<span class="string">"Ban"</span>); <span class="comment">// returns true</span>
str<span class="operator">.</span>startsWith(<span class="string">"Car"</span>); <span class="comment">// returns false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#endsWith">endsWith</a>().</p>
<h3 class="fn"><a name="startsWith-2" />bool QString.startsWith (<i>self</i>, QStringRef <i>s</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><h3 class="fn"><a name="startsWith-3" />bool QString.startsWith (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>, <a href="qt.html#CaseSensitivity-enum">Qt.CaseSensitivity</a> <i>cs</i> = Qt.CaseSensitive)</h3><p>This function overloads <a href="qstring.html#startsWith">startsWith</a>().</p>
<h3 class="fn"><a name="swap" />QString.swap (<i>self</i>, QString <i>other</i>)</h3><p>Swaps string <i>other</i> with this string. This operation is
very fast and never fails.</p>
<p>This function was introduced in Qt 4.8.</p>
<h3 class="fn"><a name="toAscii" /><a href="qbytearray.html">QByteArray</a> QString.toAscii (<i>self</i>)</h3><p>Returns an 8-bit representation of the string as a <a href="qbytearray.html">QByteArray</a>.</p>
<p>If a codec has been set using <a href="qtextcodec.html#setCodecForCStrings">QTextCodec.setCodecForCStrings</a>(),
it is used to convert Unicode to 8-bit char; otherwise this
function does the same as <a href="qstring.html#toLatin1">toLatin1</a>().</p>
<p>Note that, despite the name, this function does not necessarily
return an US-ASCII (ANSI X3.4-1986) string and its result may not
be US-ASCII compatible.</p>
<p><b>See also</b> <a href="qstring.html#fromAscii">fromAscii</a>(), <a href="qstring.html#toLatin1">toLatin1</a>(), <a href="qstring.html#toUtf8">toUtf8</a>(), <a href="qstring.html#toLocal8Bit">toLocal8Bit</a>(), and <a href="qtextcodec.html">QTextCodec</a>.</p>
<h3 class="fn"><a name="toCaseFolded" />QString QString.toCaseFolded (<i>self</i>)</h3><p>Returns the case folded equivalent of the string. For most
Unicode characters this is the same as <a href="qstring.html#toLower">toLower</a>().</p>
<h3 class="fn"><a name="toDouble" />(float, bool <i>ok</i>) QString.toDouble (<i>self</i>)</h3><p>Returns the string converted to a <tt>double</tt> value.</p>
<p>Returns 0.0 if the conversion fails.</p>
<p>If a conversion error occurs, <tt>*</tt><i>ok</i> is set to
false; otherwise <tt>*</tt><i>ok</i> is set to true.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"1234.56"</span>;
<span class="type">double</span> val <span class="operator">=</span> str<span class="operator">.</span>toDouble(); <span class="comment">// val == 1234.56</span>
</pre>
<p>Various string formats for floating point numbers can be
converted to double values:</p>
<pre class="cpp">
<span class="type">bool</span> ok;
<span class="type">double</span> d;
d <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>( <span class="string">"1234.56e-02"</span> )<span class="operator">.</span>toDouble(<span class="operator">&</span>ok); <span class="comment">// ok == true, d == 12.3456</span>
</pre>
<p>This function tries to interpret the string according to the
current locale. The current locale is determined from the system at
application startup and can be changed by calling <a href="qlocale.html#setDefault">QLocale.setDefault</a>(). If the string
cannot be interpreted according to the current locale, this
function falls back on the "C" locale.</p>
<pre class="cpp">
<span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>setDefault(<span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>C);
d <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>( <span class="string">"1234,56"</span> )<span class="operator">.</span>toDouble(<span class="operator">&</span>ok); <span class="comment">// ok == false</span>
d <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>( <span class="string">"1234.56"</span> )<span class="operator">.</span>toDouble(<span class="operator">&</span>ok); <span class="comment">// ok == true, d == 1234.56</span>
<span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>setDefault(<span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>German);
d <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>( <span class="string">"1234,56"</span> )<span class="operator">.</span>toDouble(<span class="operator">&</span>ok); <span class="comment">// ok == true, d == 1234.56</span>
d <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>( <span class="string">"1234.56"</span> )<span class="operator">.</span>toDouble(<span class="operator">&</span>ok); <span class="comment">// ok == true, d == 1234.56</span>
</pre>
<p>Due to the ambiguity between the decimal point and thousands
group separator in various locales, this function does not handle
thousands group separators. If you need to convert such numbers,
see <a href="qlocale.html#toDouble">QLocale.toDouble</a>().</p>
<pre class="cpp">
<span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>setDefault(<span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">.</span>C);
d <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>( <span class="string">"1234,56"</span> )<span class="operator">.</span>toDouble(<span class="operator">&</span>ok); <span class="comment">// ok == false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#number">number</a>(),
<a href="qlocale.html#setDefault">QLocale.setDefault</a>(),
<a href="qlocale.html#toDouble">QLocale.toDouble</a>(), and
<a href="qstring.html#trimmed">trimmed</a>().</p>
<h3 class="fn"><a name="toFloat" />(float, bool <i>ok</i>) QString.toFloat (<i>self</i>)</h3><p>Returns the string converted to a <tt>float</tt> value.</p>
<p>If a conversion error occurs, *<i>ok</i> is set to false;
otherwise *<i>ok</i> is set to true. Returns 0.0 if the conversion
fails.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str1 <span class="operator">=</span> <span class="string">"1234.56"</span>;
str1<span class="operator">.</span>toFloat(); <span class="comment">// returns 1234.56</span>
<span class="type">bool</span> ok;
<span class="type"><a href="qstring.html">QString</a></span> str2 <span class="operator">=</span> <span class="string">"R2D2"</span>;
str2<span class="operator">.</span>toFloat(<span class="operator">&</span>ok); <span class="comment">// returns 0.0, sets ok to false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#number">number</a>(),
<a href="qstring.html#toDouble">toDouble</a>(), and <a href="qstring.html#toInt">toInt</a>().</p>
<h3 class="fn"><a name="toInt" />(int, bool <i>ok</i>) QString.toInt (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the string converted to an <tt>int</tt> using base
<i>base</i>, which is 10 by default and must be between 2 and 36,
or 0. Returns 0 if the conversion fails.</p>
<p>If a conversion error occurs, *<i>ok</i> is set to false;
otherwise *<i>ok</i> is set to true.</p>
<p>If <i>base</i> is 0, the C language convention is used: If the
string begins with "0x", base 16 is used; if the string begins with
"0", base 8 is used; otherwise, base 10 is used.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"FF"</span>;
<span class="type">bool</span> ok;
<span class="type">int</span> hex <span class="operator">=</span> str<span class="operator">.</span>toInt(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">16</span>); <span class="comment">// hex == 255, ok == true</span>
<span class="type">int</span> dec <span class="operator">=</span> str<span class="operator">.</span>toInt(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">10</span>); <span class="comment">// dec == 0, ok == false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#number">number</a>(),
<a href="qstring.html#toUInt">toUInt</a>(), and <a href="qstring.html#toDouble">toDouble</a>().</p>
<h3 class="fn"><a name="toLatin1" /><a href="qbytearray.html">QByteArray</a> QString.toLatin1 (<i>self</i>)</h3><p>Returns a Latin-1 representation of the string as a <a href="qbytearray.html">QByteArray</a>.</p>
<p>The returned byte array is undefined if the string contains
non-Latin1 characters. Those characters may be suppressed or
replaced with a question mark.</p>
<p><b>See also</b> <a href="qstring.html#fromLatin1">fromLatin1</a>(), <a href="qstring.html#toAscii">toAscii</a>(), <a href="qstring.html#toUtf8">toUtf8</a>(), <a href="qstring.html#toLocal8Bit">toLocal8Bit</a>(), and <a href="qtextcodec.html">QTextCodec</a>.</p>
<h3 class="fn"><a name="toLocal8Bit" /><a href="qbytearray.html">QByteArray</a> QString.toLocal8Bit (<i>self</i>)</h3><p>Returns the local 8-bit representation of the string as a
<a href="qbytearray.html">QByteArray</a>. The returned byte array
is undefined if the string contains characters not supported by the
local 8-bit encoding.</p>
<p><a href="qtextcodec.html#codecForLocale">QTextCodec.codecForLocale</a>()
is used to perform the conversion from Unicode. If the locale
encoding could not be determined, this function does the same as
<a href="qstring.html#toLatin1">toLatin1</a>().</p>
<p>If this string contains any characters that cannot be encoded in
the locale, the returned byte array is undefined. Those characters
may be suppressed or replaced by another.</p>
<p><b>See also</b> <a href="qstring.html#fromLocal8Bit">fromLocal8Bit</a>(), <a href="qstring.html#toAscii">toAscii</a>(), <a href="qstring.html#toLatin1">toLatin1</a>(), <a href="qstring.html#toUtf8">toUtf8</a>(), and <a href="qtextcodec.html">QTextCodec</a>.</p>
<h3 class="fn"><a name="toLong" />(int, bool <i>ok</i>) QString.toLong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the string converted to a <tt>long</tt> using base
<i>base</i>, which is 10 by default and must be between 2 and 36,
or 0. Returns 0 if the conversion fails.</p>
<p>If a conversion error occurs, *<i>ok</i> is set to false;
otherwise *<i>ok</i> is set to true.</p>
<p>If <i>base</i> is 0, the C language convention is used: If the
string begins with "0x", base 16 is used; if the string begins with
"0", base 8 is used; otherwise, base 10 is used.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"FF"</span>;
<span class="type">bool</span> ok;
<span class="type">long</span> hex <span class="operator">=</span> str<span class="operator">.</span>toLong(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">16</span>); <span class="comment">// hex == 255, ok == true</span>
<span class="type">long</span> dec <span class="operator">=</span> str<span class="operator">.</span>toLong(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">10</span>); <span class="comment">// dec == 0, ok == false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#number">number</a>(),
<a href="qstring.html#toULong">toULong</a>(), and <a href="qstring.html#toInt">toInt</a>().</p>
<h3 class="fn"><a name="toLongLong" />(int, bool <i>ok</i>) QString.toLongLong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the string converted to a <tt>long long</tt> using base
<i>base</i>, which is 10 by default and must be between 2 and 36,
or 0. Returns 0 if the conversion fails.</p>
<p>If a conversion error occurs, *<i>ok</i> is set to false;
otherwise *<i>ok</i> is set to true.</p>
<p>If <i>base</i> is 0, the C language convention is used: If the
string begins with "0x", base 16 is used; if the string begins with
"0", base 8 is used; otherwise, base 10 is used.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"FF"</span>;
<span class="type">bool</span> ok;
<span class="type"><a href="qtcore.html#qint64-typedef">long</a></span> hex <span class="operator">=</span> str<span class="operator">.</span>toLongLong(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">16</span>); <span class="comment">// hex == 255, ok == true</span>
<span class="type"><a href="qtcore.html#qint64-typedef">long</a></span> dec <span class="operator">=</span> str<span class="operator">.</span>toLongLong(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">10</span>); <span class="comment">// dec == 0, ok == false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#number">number</a>(),
<a href="qstring.html#toULongLong">toULongLong</a>(), and <a href="qstring.html#toInt">toInt</a>().</p>
<h3 class="fn"><a name="toLower" />QString QString.toLower (<i>self</i>)</h3><p>Returns a lowercase copy of the string.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"Qt by NOKIA"</span>;
str <span class="operator">=</span> str<span class="operator">.</span>toLower(); <span class="comment">// str == "qt by nokia"</span>
</pre>
<p>The case conversion will always happen in the 'C' locale. For
locale dependent case folding use <a href="qlocale.html#toLower">QLocale.toLower</a>()</p>
<p><b>See also</b> <a href="qstring.html#toUpper">toUpper</a>() and
<a href="qlocale.html#toLower">QLocale.toLower</a>().</p>
<h3 class="fn"><a name="toShort" />(int, bool <i>ok</i>) QString.toShort (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the string converted to a <tt>short</tt> using base
<i>base</i>, which is 10 by default and must be between 2 and 36,
or 0. Returns 0 if the conversion fails.</p>
<p>If a conversion error occurs, *<i>ok</i> is set to false;
otherwise *<i>ok</i> is set to true.</p>
<p>If <i>base</i> is 0, the C language convention is used: If the
string begins with "0x", base 16 is used; if the string begins with
"0", base 8 is used; otherwise, base 10 is used.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"FF"</span>;
<span class="type">bool</span> ok;
<span class="type">short</span> hex <span class="operator">=</span> str<span class="operator">.</span>toShort(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">16</span>); <span class="comment">// hex == 255, ok == true</span>
<span class="type">short</span> dec <span class="operator">=</span> str<span class="operator">.</span>toShort(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">10</span>); <span class="comment">// dec == 0, ok == false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#number">number</a>(),
<a href="qstring.html#toUShort">toUShort</a>(), and <a href="qstring.html#toInt">toInt</a>().</p>
<h3 class="fn"><a name="toUInt" />(int, bool <i>ok</i>) QString.toUInt (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the string converted to an <tt>unsigned int</tt> using
base <i>base</i>, which is 10 by default and must be between 2 and
36, or 0. Returns 0 if the conversion fails.</p>
<p>If a conversion error occurs, *<i>ok</i> is set to false;
otherwise *<i>ok</i> is set to true.</p>
<p>If <i>base</i> is 0, the C language convention is used: If the
string begins with "0x", base 16 is used; if the string begins with
"0", base 8 is used; otherwise, base 10 is used.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"FF"</span>;
<span class="type">bool</span> ok;
<span class="type"><a href="qtcore.html#uint-typedef">uint</a></span> hex <span class="operator">=</span> str<span class="operator">.</span>toUInt(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">16</span>); <span class="comment">// hex == 255, ok == true</span>
<span class="type"><a href="qtcore.html#uint-typedef">uint</a></span> dec <span class="operator">=</span> str<span class="operator">.</span>toUInt(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">10</span>); <span class="comment">// dec == 0, ok == false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#number">number</a>() and
<a href="qstring.html#toInt">toInt</a>().</p>
<h3 class="fn"><a name="toULong" />(int, bool <i>ok</i>) QString.toULong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the string converted to an <tt>unsigned long</tt> using
base <i>base</i>, which is 10 by default and must be between 2 and
36, or 0. Returns 0 if the conversion fails.</p>
<p>If a conversion error occurs, *<i>ok</i> is set to false;
otherwise *<i>ok</i> is set to true.</p>
<p>If <i>base</i> is 0, the C language convention is used: If the
string begins with "0x", base 16 is used; if the string begins with
"0", base 8 is used; otherwise, base 10 is used.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"FF"</span>;
<span class="type">bool</span> ok;
<span class="type"><a href="qtcore.html#ulong-typedef">ulong</a></span> hex <span class="operator">=</span> str<span class="operator">.</span>toULong(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">16</span>); <span class="comment">// hex == 255, ok == true</span>
<span class="type"><a href="qtcore.html#ulong-typedef">ulong</a></span> dec <span class="operator">=</span> str<span class="operator">.</span>toULong(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">10</span>); <span class="comment">// dec == 0, ok == false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#number">number</a>().</p>
<h3 class="fn"><a name="toULongLong" />(int, bool <i>ok</i>) QString.toULongLong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the string converted to an <tt>unsigned long long</tt>
using base <i>base</i>, which is 10 by default and must be between
2 and 36, or 0. Returns 0 if the conversion fails.</p>
<p>If a conversion error occurs, *<i>ok</i> is set to false;
otherwise *<i>ok</i> is set to true.</p>
<p>If <i>base</i> is 0, the C language convention is used: If the
string begins with "0x", base 16 is used; if the string begins with
"0", base 8 is used; otherwise, base 10 is used.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"FF"</span>;
<span class="type">bool</span> ok;
<span class="type"><a href="qtcore.html#quint64-typedef">unsigned long</a></span> hex <span class="operator">=</span> str<span class="operator">.</span>toULongLong(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">16</span>); <span class="comment">// hex == 255, ok == true</span>
<span class="type"><a href="qtcore.html#quint64-typedef">unsigned long</a></span> dec <span class="operator">=</span> str<span class="operator">.</span>toULongLong(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">10</span>); <span class="comment">// dec == 0, ok == false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#number">number</a>() and
<a href="qstring.html#toLongLong">toLongLong</a>().</p>
<h3 class="fn"><a name="toUpper" />QString QString.toUpper (<i>self</i>)</h3><p>Returns an uppercase copy of the string.</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"TeXt"</span>;
str <span class="operator">=</span> str<span class="operator">.</span>toUpper(); <span class="comment">// str == "TEXT"</span>
</pre>
<p>The case conversion will always happen in the 'C' locale. For
locale dependent case folding use <a href="qlocale.html#toUpper">QLocale.toUpper</a>()</p>
<p><b>See also</b> <a href="qstring.html#toLower">toLower</a>() and
<a href="qlocale.html#toLower">QLocale.toLower</a>().</p>
<h3 class="fn"><a name="toUShort" />(int, bool <i>ok</i>) QString.toUShort (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the string converted to an <tt>unsigned short</tt> using
base <i>base</i>, which is 10 by default and must be between 2 and
36, or 0. Returns 0 if the conversion fails.</p>
<p>If a conversion error occurs, *<i>ok</i> is set to false;
otherwise *<i>ok</i> is set to true.</p>
<p>If <i>base</i> is 0, the C language convention is used: If the
string begins with "0x", base 16 is used; if the string begins with
"0", base 8 is used; otherwise, base 10 is used.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"FF"</span>;
<span class="type">bool</span> ok;
<span class="type"><a href="qtcore.html#ushort-typedef">ushort</a></span> hex <span class="operator">=</span> str<span class="operator">.</span>toUShort(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">16</span>); <span class="comment">// hex == 255, ok == true</span>
<span class="type"><a href="qtcore.html#ushort-typedef">ushort</a></span> dec <span class="operator">=</span> str<span class="operator">.</span>toUShort(<span class="operator">&</span>ok<span class="operator">,</span> <span class="number">10</span>); <span class="comment">// dec == 0, ok == false</span>
</pre>
<p><b>See also</b> <a href="qstring.html#number">number</a>() and
<a href="qstring.html#toShort">toShort</a>().</p>
<h3 class="fn"><a name="toUtf8" /><a href="qbytearray.html">QByteArray</a> QString.toUtf8 (<i>self</i>)</h3><p>Returns a UTF-8 representation of the string as a <a href="qbytearray.html">QByteArray</a>.</p>
<p>UTF-8 is a Unicode codec and can represent all characters in a
Unicode string like <a href="qstring.html">QString</a>.</p>
<p>However, in the Unicode range, there are certain codepoints that
are not considered characters. The Unicode standard reserves the
last two codepoints in each Unicode Plane (U+FFFE, U+FFFF, U+1FFFE,
U+1FFFF, U+2FFFE, etc.), as well as 16 codepoints in the range
U+FDD0..U+FDDF, inclusive, as non-characters. If any of those
appear in the string, they may be discarded and will not appear in
the UTF-8 representation, or they may be replaced by one or more
replacement characters.</p>
<p><b>See also</b> <a href="qstring.html#fromUtf8">fromUtf8</a>(),
<a href="qstring.html#toAscii">toAscii</a>(), <a href="qstring.html#toLatin1">toLatin1</a>(), <a href="qstring.html#toLocal8Bit">toLocal8Bit</a>(), and <a href="qtextcodec.html">QTextCodec</a>.</p>
<h3 class="fn"><a name="trimmed" />QString QString.trimmed (<i>self</i>)</h3><p>Returns a string that has whitespace removed from the start and
the end.</p>
<p>Whitespace means any character for which <a href="qchar.html#isSpace">QChar.isSpace</a>() returns true. This
includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and '
'.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">" lots\t of\nwhitespace\r\n "</span>;
str <span class="operator">=</span> str<span class="operator">.</span>trimmed();
<span class="comment">// str == "lots\t of\nwhitespace"</span>
</pre>
<p>Unlike <a href="qstring.html#simplified">simplified</a>(),
trimmed() leaves internal whitespace alone.</p>
<p><b>See also</b> <a href="qstring.html#simplified">simplified</a>().</p>
<h3 class="fn"><a name="truncate" />QString.truncate (<i>self</i>, int <i>pos</i>)</h3><p>Truncates the string at the given <i>position</i> index.</p>
<p>If the specified <i>position</i> index is beyond the end of the
string, nothing happens.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qstring.html">QString</a></span> str <span class="operator">=</span> <span class="string">"Vladivostok"</span>;
str<span class="operator">.</span>truncate(<span class="number">4</span>);
<span class="comment">// str == "Vlad"</span>
</pre>
<p>If <i>position</i> is negative, it is equivalent to passing
zero.</p>
<p><b>See also</b> <a href="qstring.html#chop">chop</a>(), <a href="qstring.html#resize">resize</a>(), and <a href="qstring.html#left">left</a>().</p>
<h3 class="fn"><a name="__add__" />QString QString.__add__ (<i>self</i>, QString <i>s2</i>)</h3><h3 class="fn"><a name="__add__-2" />QString QString.__add__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>ba</i>)</h3><h3 class="fn"><a name="__contains__" />int QString.__contains__ (<i>self</i>, QString <i>s</i>)</h3><h3 class="fn"><a name="__eq__" />bool QString.__eq__ (<i>self</i>, QString <i>s</i>)</h3><h3 class="fn"><a name="__eq__-2" />bool QString.__eq__ (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>)</h3><h3 class="fn"><a name="__eq__-3" />bool QString.__eq__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>s</i>)</h3><h3 class="fn"><a name="__eq__-4" />bool QString.__eq__ (<i>self</i>, QStringRef <i>s2</i>)</h3><h3 class="fn"><a name="__ge__" />bool QString.__ge__ (<i>self</i>, QString <i>s</i>)</h3><h3 class="fn"><a name="__ge__-2" />bool QString.__ge__ (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>)</h3><h3 class="fn"><a name="__ge__-3" />bool QString.__ge__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>s</i>)</h3><h3 class="fn"><a name="__getitem__" />QString QString.__getitem__ (<i>self</i>, int <i>i</i>)</h3><h3 class="fn"><a name="__getitem__-2" />QString QString.__getitem__ (<i>self</i>, slice <i>slice</i>)</h3><h3 class="fn"><a name="__gt__" />bool QString.__gt__ (<i>self</i>, QString <i>s</i>)</h3><h3 class="fn"><a name="__gt__-2" />bool QString.__gt__ (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>)</h3><h3 class="fn"><a name="__gt__-3" />bool QString.__gt__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>s</i>)</h3><h3 class="fn"><a name="__hash__" />int QString.__hash__ (<i>self</i>)</h3><h3 class="fn"><a name="__iadd__" />QString QString.__iadd__ (<i>self</i>, <a href="qchar.html#SpecialCharacter-enum">QChar.SpecialCharacter</a> <i>c</i>)</h3><h3 class="fn"><a name="__iadd__-2" />QString QString.__iadd__ (<i>self</i>, QString <i>s</i>)</h3><h3 class="fn"><a name="__iadd__-3" />QString QString.__iadd__ (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>)</h3><h3 class="fn"><a name="__iadd__-4" />QString QString.__iadd__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>s</i>)</h3><h3 class="fn"><a name="__imul__" />QString QString.__imul__ (<i>self</i>, int <i>m</i>)</h3><h3 class="fn"><a name="__le__" />bool QString.__le__ (<i>self</i>, QString <i>s</i>)</h3><h3 class="fn"><a name="__le__-2" />bool QString.__le__ (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>)</h3><h3 class="fn"><a name="__le__-3" />bool QString.__le__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>s</i>)</h3><h3 class="fn"><a name="__len__" /> QString.__len__ (<i>self</i>)</h3><h3 class="fn"><a name="__lt__" />bool QString.__lt__ (<i>self</i>, QString <i>s</i>)</h3><h3 class="fn"><a name="__lt__-2" />bool QString.__lt__ (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>)</h3><h3 class="fn"><a name="__lt__-3" />bool QString.__lt__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>s</i>)</h3><h3 class="fn"><a name="__mul__" />QString QString.__mul__ (<i>self</i>, int <i>m</i>)</h3><h3 class="fn"><a name="__ne__" />bool QString.__ne__ (<i>self</i>, QString <i>s</i>)</h3><h3 class="fn"><a name="__ne__-2" />bool QString.__ne__ (<i>self</i>, <a href="qlatin1string.html">QLatin1String</a> <i>s</i>)</h3><h3 class="fn"><a name="__ne__-3" />bool QString.__ne__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>s</i>)</h3><h3 class="fn"><a name="__ne__-4" />bool QString.__ne__ (<i>self</i>, QStringRef <i>s2</i>)</h3><h3 class="fn"><a name="__repr__" />str QString.__repr__ (<i>self</i>)</h3><h3 class="fn"><a name="__str__" />str QString.__str__ (<i>self</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.11.4 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qt.io">The Qt Company</a> 2015</td><td align="right" width="25%">Qt 4.8.7</td></tr></table></div></address></body></html>
|