当前位置: 首页>>代码示例>>C++>>正文


C++ String::CharAt方法代码示例

本文整理汇总了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;
}
开发者ID:erenik,项目名称:engine,代码行数:21,代码来源:StringUtil.cpp

示例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;
}
开发者ID:willcassella,项目名称:WillowEngine,代码行数:12,代码来源:String.cpp

示例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;
}
开发者ID:willcassella,项目名称:WillowEngine,代码行数:12,代码来源:String.cpp

示例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
//.........这里部分代码省略.........
开发者ID:erenik,项目名称:engine,代码行数:101,代码来源:SIPPacket.cpp


注:本文中的String::CharAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。