本文整理汇总了C++中String::CharAt方法的典型用法代码示例。如果您正苦于以下问题:C++ String::CharAt方法的具体用法?C++ String::CharAt怎么用?C++ String::CharAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::CharAt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetSection
/// Fetches target section in string using given start and end-tokens. Returns the first occurance, if any, or an empty string if none such exist.
String GetSection(String inString, char withStartToken, char andEndToken){
int startIndex = -1, endIndex = -1;
for (int i = 0; i < inString.Length(); ++i){
char c = inString.CharAt(i);
if (c == withStartToken)
startIndex = i+1;
if (c == andEndToken)
endIndex = i;
if (startIndex >= 0 && endIndex >= 0)
break;
}
if (startIndex < 0 && endIndex < 0)
return String();
String newString;
for (int i = startIndex; i < endIndex; ++i){
newString.Add(inString.CharAt(i));
}
std::cout<<"newString: "<<newString<<" length: "<<newString.Length();
return newString;
}
示例2: EndsWith
bool String::EndsWith(const String& string) const
{
for (std::size_t i = 1; i <= string.Length(); ++i)
{
if (this->CharAt(this->Length() - i) != string.CharAt(string.Length() - i))
{
return false;
}
}
return true;
}
示例3: StartsWith
bool String::StartsWith(const String& string) const
{
for (std::size_t i = 0; i < string.Length(); ++i)
{
if (this->CharAt(i) != string.CharAt(i))
{
return false;
}
}
return true;
}
示例4: ParseHeader
// Fetches type-integer from the header-data. See above for RFC details.
void SIPPacket::ParseHeader(){
// std::cout << "SIPPacket::ParseHeader called.";
String line;
List<String> tokens;
sipType = SIP_NULL;
// Evaluate basic type of the packet, first need to get the first valid line...
String firstLine;
int firstLineIndex;
for (int i = 0; i < header.Size(); ++i){
firstLine = header[i];
if (firstLine.Length()){
firstLineIndex = i;
break;
}
}
// Determine type from first line
for (int i = 0; i < SIP_PACKET_TYPES; ++i){
String typeName = PacketTypeName(i);
if (firstLine.Contains(typeName)){
sipType = i;
break;
}
}
// Try and see if it's a numerical response-code we don't know?
if (sipType == SIP_NULL){
// Split using white-space, get first element, try and parse numberrr!
String firstPart = firstLine.Tokenize(" \t\n\r")[0];
int number = firstPart.ParseInt();
if (number >= 700)
sipType = SIP_NULL;
else if (number >= 600)
sipType = SIP_GLOBAL_FAILURE;
else if (number >= 500)
sipType = SIP_SERVER_INTERNAL_ERROR;
else if (number >= 400)
sipType = SIP_BAD_REQUEST;
else if (number >= 300)
sipType = SIP_REDIRECTION;
else if (number >= 200)
sipType = SIP_OK; // Should not even get here, but eh..
else if (number >= 100)
sipType = SIP_PROVISIONAL;
}
// If still bad type, don't parse anymore? :|
if (sipType == SIP_NULL){
// std::cout <<"Type of packet could not be determined in SIPPacket::ParseHeader, firstline: "<<firstLine;
return;
}
// Evaluate the rest of the lines
for (int i = firstLineIndex+1; i < header.Size(); ++i){
line = header[i];
// Split using all white-space characters and the colon for header-fields!
// First find where attribute name and value start/end (the first colon)
String attributeName = String();
String attributeValue = String();
// Remove only up to the first colon?
int firstColonIndex = -1;
for(int i = 0; i < line.Length(); ++i){
if (line.CharAt(i) == ':'){
firstColonIndex = i;
break;
}
}
attributeName = line.Part(0, firstColonIndex);
attributeValue = line.Part(firstColonIndex+1);
attributeName.RemoveInitialWhitespaces();
attributeValue.RemoveInitialWhitespaces();
// Macro for the comparison, getting tired of this...
// First macro checks if they are lexicographically the same (i.e. identical), except not case sensitive
#define IsAttributeName(a) (attributeName == a)
// And the second macros does the same but compares if it is either the same to a OR b, inclusive.
#define IsAttributeName2(a,b) (IsAttributeName(a) || IsAttributeName(b))
// Set comparison mode to not case sensitive.
attributeName.SetComparisonMode(String::NOT_CASE_SENSITIVE);
// Apparently all fields can have compact forms too, so spam all the comparisons..
if (IsAttributeName2("Call-ID","i")){
callID = attributeValue;
}
else if (IsAttributeName2("Content-Length","l")){
String s = attributeValue;
contentLength = s.ParseInt();
}
else if (IsAttributeName2("Content-Type","c")){
contentType = attributeValue;
}
else if (IsAttributeName("CSeq")){
cSeq = attributeValue;
}
else if (IsAttributeName("Expires")){
String s = attributeValue;
expirationTime = s.ParseInt();
}
else if (IsAttributeName2("From","f")){
senderData = attributeValue;
}
else if (IsAttributeName("Require")){
// Although an optional header field, the Require MUST NOT be
//.........这里部分代码省略.........