Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Split a String using a Delimiter Char
How to split a string using a delimiter. CkString str; str.append("\"Chilkat Software, Inc.\", http://www.chilkatsoft.com, \"Email, Zip, Encryption, XML\""); bool exceptDoubleQuoted = true; bool exceptEscaped = true; // Do not treat characters preceded with a backslash as a delimiter. bool keepEmpty = false; // Do not keep empty fields. char delimiter = ','; CkStringArray *array = str.split(delimiter,exceptDoubleQuoted,exceptEscaped,keepEmpty); int i; for (i=0; i<array->get_Count(); i++) { printf("%d: [%s]\n",i,array->GetString(i)); } // Prints: // 0: ["Chilkat Software, Inc."] // 1: [ http://www.chilkatsoft.com] // 2: [ "Email, Zip, Encryption, XML"] // Clean it up... CkString tempStr; for (i=0; i<array->get_Count(); i++) { array->GetString(i,tempStr); tempStr.trim(); // Trim whitespace from ends. tempStr.removeCharOccurances('"'); // Remove double quotes. printf("%d: [%s]\n",i,tempStr.getString()); } // Prints: // 0: [Chilkat Software, Inc.] // 1: [http://www.chilkatsoft.com] // 2: [Email, Zip, Encryption, XML] delete array;
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.