General/Strings
(→strcat) |
(→strcat) |
||
| (16 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | <yambe:breadcrumb self="Strings">General|General Programming</yambe:breadcrumb> | |
| − | + | <br /> | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | {| | + | {| |
|- | |- | ||
| − | |''For information about displaying on the | + | |''For information about displaying on the NXT LCD, please see the article: [[NXT_Functions_Display|NXT Display Functions]].'' |
| + | |||
| + | ''For information about displaying on the VEX LCD, please see the article: [[VEX2_Functions_Display|Cortex Display Functions]].'' | ||
| Line 17: | Line 14: | ||
|- | |- | ||
|} | |} | ||
| + | <br /> | ||
| + | {{tl|1|1}} | ||
| + | <br /> | ||
| − | {| | + | == sprintf == |
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | | + | | class="functionType"| |
| − | + | <span class="bigKeywordBI">void </span> | |
| − | + | <span class="bigKeywordB">sprintf</span> | |
| − | + | <span class="bigCodePunc">(</span> | |
| − | + | <span class="bigKeywordBI">string </span> | |
| − | + | <span class="bigCodeBasic">&sString</span> | |
| − | + | <span class="bigCodePunc">, </span> | |
| − | + | <span class="bigKeywordBI">const string </span> | |
| − | + | <span class="bigCodeBasic">sFormatString</span> | |
| − | + | <span class="bigCodePunc">, </span> | |
| − | + | <span class="bigCodeBasic">...</span> | |
| + | <span class="bigCodePunc">)</span> | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) This function writes the data from <span class="codeBasic">sFormatString</span> to <span class="codeBasic">&sString</span>. Identical to the function found in conventional C 'string.h' library. | ||
| + | |- | ||
| + | | | ||
| + | {| class="parameterTable" cellpadding="5%" width="100%" | ||
| + | ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter | ||
| + | ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation | ||
| + | ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 1px 0px 1px 0px"|''&sString'' | ||
| + | | style="border-style: solid; border-width: 1px 0px 1px 0px"|This is the destination string. | ||
| + | | style="border-style: solid; border-width: 1px 0px 1px 0px"|[[Data_Types#dataType_string|string]] | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''sFormatString, ...'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|These are the source strings. | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_string|string]] | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | | | ||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | task main() | ||
| + | { | ||
| + | string srce = "ROBOTC"; // create source variable 'srce' and set it to "ROBOTC" | ||
| + | string dest; // create destination variable 'dest' | ||
| + | |||
| + | wait1Msec(1000); // wait 1 second | ||
| + | |||
| + | sprintf(dest, srce); // write to 'dest', the contents of 'srce' (dest <- "ROBOTC) | ||
| + | |||
| + | while(true); // infinite loop (so we can watch the debbugger) | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
|- | |- | ||
|} | |} | ||
| + | <br /> | ||
| + | <!-- BROKEN | ||
| + | == sprintf == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | class="functionType"| | ||
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigKeywordB">sprintf</span> | ||
| + | <span class="bigCodePunc">(</span> | ||
| + | <span class="bigKeywordBI">string </span> | ||
| + | <span class="bigCodeBasic">&sString</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const string </span> | ||
| + | <span class="bigCodeBasic">sFormatString</span> | ||
| + | <span class="bigCodePunc">, )</span> | ||
| + | <span class="bigCodeBasic">...</span> | ||
| + | <span class="bigCodePunc">)</span> | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) This function writes the data from <span class="codeBasic">sFormatString</span> to <span class="codeBasic">&sString</span>. Identical to the function found in conventional C 'string.h' library. | ||
| + | |- | ||
| + | | | ||
| + | {| class="parameterTable" cellpadding="5%" width="100%" | ||
| + | ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter | ||
| + | ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation | ||
| + | ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 1px 0px 1px 0px"|''&sString'' | ||
| + | | style="border-style: solid; border-width: 1px 0px 1px 0px"|This is the destination string. | ||
| + | | style="border-style: solid; border-width: 1px 0px 1px 0px"|[[Data_Types#dataType_void|void]] | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''sFormatString, ...'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|These are the source strings. | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_void|void]] | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | | | ||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | task main() | ||
| + | { | ||
| + | string srce = "ROBOTC"; // create source variable 'srce' and set it to "ROBOTC" | ||
| + | string dest; // create destination variable 'dest' | ||
| + | |||
| + | wait1Msec(1000); // wait 1 second | ||
| + | |||
| + | sprintf(dest, srce); // write to 'dest', the contents of 'srce' (dest <- "ROBOTC) | ||
| + | |||
| + | while(true); // infinite loop (so we can watch the debbugger) | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | <br /> | ||
| + | --> | ||
== strcat == | == strcat == | ||
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">strcat</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">void </span><span class="bigCodeBasic">&pToBuffer</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const void </span><span class="bigCodeBasic">&pFromBuffer</span><span class="bigCodePunc">)</span> | + | | class="functionType"| |
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigKeywordB">strcat</span> | ||
| + | <span class="bigCodePunc">(</span> | ||
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigCodeBasic">&pToBuffer</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const void </span> | ||
| + | <span class="bigCodeBasic">&pFromBuffer</span> | ||
| + | <span class="bigCodePunc">)</span> | ||
|- | |- | ||
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Function concatenates <span class="codeBasic">pFromBuffer</span> onto end of <span class="codeBasic">pToBuffer</span>. The variables are arrays of bytes terminated with zero character. It is user responsibility to ensure that the 'To' array is large enough to hold the result. ROBOTC is not able to do any range checking! Identical to the function found in conventional C 'string.h' library. | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Function concatenates <span class="codeBasic">pFromBuffer</span> onto end of <span class="codeBasic">pToBuffer</span>. The variables are arrays of bytes terminated with zero character. It is user responsibility to ensure that the 'To' array is large enough to hold the result. ROBOTC is not able to do any range checking! Identical to the function found in conventional C 'string.h' library. | ||
| Line 68: | Line 174: | ||
strcat(str1, str2); // concatinate string 'str2' onto string 'str1' | strcat(str1, str2); // concatinate string 'str2' onto string 'str1' | ||
| − | + | while(true); // infinite loop (to keep debugger running) | |
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
| Line 79: | Line 185: | ||
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | class="functionType"| <span class="bigKeywordBI">short </span><span class="bigKeywordB">strcmp</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">void </span><span class="bigCodeBasic">&pString1</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const void </span><span class="bigCodeBasic">&pString2</span><span class="bigCodePunc">)</span> | + | | class="functionType"| |
| + | <span class="bigKeywordBI">short </span> | ||
| + | <span class="bigKeywordB">strcmp</span> | ||
| + | <span class="bigCodePunc">(</span> | ||
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigCodeBasic">&pString1</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const void </span> | ||
| + | <span class="bigCodeBasic">&pString2</span> | ||
| + | <span class="bigCodePunc">)</span> | ||
|- | |- | ||
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_short|short]]) Function compares <span class="codeBasic">pString1</span> with <span class="codeBasic">pString2</span>. Returns negative value if less than, 0 if equal and positive value if greater than. The variables are arrays of bytes terminated with a zero char. Identical to the function found in conventional C 'string.h' library. | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_short|short]]) Function compares <span class="codeBasic">pString1</span> with <span class="codeBasic">pString2</span>. Returns negative value if less than, 0 if equal and positive value if greater than. The variables are arrays of bytes terminated with a zero char. Identical to the function found in conventional C 'string.h' library. | ||
| Line 108: | Line 223: | ||
if(strcmp(str1, str2) < 0) // if 'str1' < 'str2': | if(strcmp(str1, str2) < 0) // if 'str1' < 'str2': | ||
{ | { | ||
| − | + | // 'str1' is < 'str2' | |
} | } | ||
else if(strcmp(str1, str2) > 0) // if 'str1' > 'str2': | else if(strcmp(str1, str2) > 0) // if 'str1' > 'str2': | ||
{ | { | ||
| − | + | // 'str1' is > 'str2' | |
} | } | ||
else // if 'str1' == 'str2': | else // if 'str1' == 'str2': | ||
{ | { | ||
| − | + | // 'str1' is = 'str2' | |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 128: | Line 243: | ||
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">strcpy</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">void </span><span class="bigCodeBasic">&pToBuffer</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const void </span><span class="bigCodeBasic">&pFromBuffer</span><span class="bigCodePunc">)</span> | + | | class="functionType"| |
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigKeywordB">strcpy</span> | ||
| + | <span class="bigCodePunc">(</span> | ||
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigCodeBasic">&pToBuffer</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const void </span> | ||
| + | <span class="bigCodeBasic">&pFromBuffer</span> | ||
| + | <span class="bigCodePunc">)</span> | ||
|- | |- | ||
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Function copies <span class="codeBasic">pFromBuffer</span> to <span class="codeBasic">pToBuffer</span>. The variables are arrays of bytes terminated with a zero character. It is user responsibility to ensure that the 'To' array is large enough to hold the result. ROBOTC is not able to do any range checking! Identical to the function found in conventional C 'string.h' library. | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Function copies <span class="codeBasic">pFromBuffer</span> to <span class="codeBasic">pToBuffer</span>. The variables are arrays of bytes terminated with a zero character. It is user responsibility to ensure that the 'To' array is large enough to hold the result. ROBOTC is not able to do any range checking! Identical to the function found in conventional C 'string.h' library. | ||
| Line 152: | Line 276: | ||
|- | |- | ||
|<syntaxhighlight lang="ROBOTC"> | |<syntaxhighlight lang="ROBOTC"> | ||
| − | string str1 = ""; | + | string str1 = ""; // 'str1' is "" (empty) |
| − | string str2 = "DNA"; | + | string str2 = "DNA"; // string 'str2' is "DNA" |
| − | strcpy(str1, str2); | + | strcpy(str1, str2); // copy string 'str2' onto string 'str1' |
| − | + | while(true); // infinite loop (to keep debugger running) | |
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
| Line 168: | Line 292: | ||
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">StringDelete</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">string </span><span class="bigCodeBasic">&sDest</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const int </span><span class="bigCodeBasic">nIndex</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const int </span><span class="bigCodeBasic">nSize</span><span class="bigCodePunc">)</span> | + | | class="functionType"| |
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigKeywordB">StringDelete</span> | ||
| + | <span class="bigCodePunc">(</span> | ||
| + | <span class="bigKeywordBI">string </span> | ||
| + | <span class="bigCodeBasic">&sDest</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const int </span> | ||
| + | <span class="bigCodeBasic">nIndex</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const int </span> | ||
| + | <span class="bigCodeBasic">nSize</span> | ||
| + | <span class="bigCodePunc">)</span> | ||
|- | |- | ||
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Deletes a substring from a string. | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Deletes a substring from a string. | ||
| Line 196: | Line 332: | ||
|- | |- | ||
|<syntaxhighlight lang="ROBOTC"> | |<syntaxhighlight lang="ROBOTC"> | ||
| − | string str = "mesGARBAGEsage"; | + | string str = "mesGARBAGEsage"; // String 'str' is "mesGARBAGEsage". |
| − | StringDelete(str, 3, 7); | + | StringDelete(str, 3, 7); // Delete from index 3 to the 7th char after that. |
| − | + | /* Confusing because 3 = index 3, not char 3. Since indexing */ | |
| − | + | /* starts with 0, index 3 is the 4th character. */ | |
| − | + | while(true); // infinite loop (to keep debugger running) | |
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
| Line 213: | Line 349: | ||
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | class="functionType"| <span class="bigKeywordBI">int </span><span class="bigKeywordB">StringFind</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const string </span><span class="bigCodeBasic">&sSrce</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const string </span><span class="bigCodeBasic">&sSearch</span><span class="bigCodePunc">)</span> | + | | class="functionType"| |
| + | <span class="bigKeywordBI">int </span> | ||
| + | <span class="bigKeywordB">StringFind</span> | ||
| + | <span class="bigCodePunc">(</span> | ||
| + | <span class="bigKeywordBI">const string </span> | ||
| + | <span class="bigCodeBasic">&sSrce</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const string </span> | ||
| + | <span class="bigCodeBasic">&sSearch</span> | ||
| + | <span class="bigCodePunc">)</span> | ||
|- | |- | ||
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_int|int]]) Finds the position in a string of the selected substring. | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_int|int]]) Finds the position in a string of the selected substring. | ||
| Line 237: | Line 382: | ||
|- | |- | ||
|<syntaxhighlight lang="ROBOTC"> | |<syntaxhighlight lang="ROBOTC"> | ||
| − | string str = "mesHIDDENsage"; | + | string str = "mesHIDDENsage"; // String 'str' is "mesGARBAGEsage". |
| − | int index_of_substr; | + | int index_of_substr; // Int, 'index_of_substr' to be used by "StringFind()". |
| − | index_of_substr = StringFind(str_msg, "HIDDEN"); | + | index_of_substr = StringFind(str_msg, "HIDDEN"); /* Search for the substring, "HIDDEN" */ |
| − | + | /* withing the string, 'str'. */ | |
| − | + | while(true); // infinite loop (to keep debugger running) | |
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
| Line 254: | Line 399: | ||
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">StringFormat</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">string </span><span class="bigCodeBasic">&sDest</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const string </span><span class="bigCodeBasic">sFormatString</span><span class="bigCodePunc">, </span><span class="bigCodeBasic">...</span><span class="bigCodePunc">)</span> | + | | class="functionType"| |
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigKeywordB">StringFormat</span> | ||
| + | <span class="bigCodePunc">(</span> | ||
| + | <span class="bigKeywordBI">string </span> | ||
| + | <span class="bigCodeBasic">&sDest</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const string </span> | ||
| + | <span class="bigCodeBasic">sFormatString</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigCodeBasic">...</span> | ||
| + | <span class="bigCodePunc">)</span> | ||
|- | |- | ||
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Formats a string using the specified format-string. | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Formats a string using the specified format-string. | ||
| Line 278: | Line 434: | ||
|- | |- | ||
|<syntaxhighlight lang="ROBOTC"> | |<syntaxhighlight lang="ROBOTC"> | ||
| − | string str = ""; | + | string str = ""; // Create String, 'str' and initialize it as 'empty'. |
| − | float num = 3.14159; | + | float num = 3.14159; // Create float, 'num' and initialize it as first 6 digits of pi. |
| − | StringFormat(str, "%1.2f", num); | + | StringFormat(str, "%1.2f", num); /* Format num into a float to 2 decimal places, then send it to |
| − | + | the string, 'str'. */ | |
| − | + | while(true); // infinite loop (to keep debugger running) | |
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
| Line 294: | Line 450: | ||
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">StringFromChars</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">string </span><span class="bigCodeBasic">&sToString</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const char </span><span class="bigCodeBasic">&FromChars</span><span class="bigCodePunc">)</span> | + | | class="functionType"| |
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigKeywordB">StringFromChars</span> | ||
| + | <span class="bigCodePunc">(</span> | ||
| + | <span class="bigKeywordBI">string </span> | ||
| + | <span class="bigCodeBasic">&sToString</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const char </span> | ||
| + | <span class="bigCodeBasic">&FromChars</span> | ||
| + | <span class="bigCodePunc">)</span> | ||
|- | |- | ||
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Converts an array of bytes to a string value. You MUST end your char array with a char value of zero! | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Converts an array of bytes to a string value. You MUST end your char array with a char value of zero! | ||
| Line 332: | Line 497: | ||
test[9] = 'X'; /* since they are after the zero */ | test[9] = 'X'; /* since they are after the zero */ | ||
| − | StringFromChars(str, test); | + | StringFromChars(str, test); // copy chars from 'test' to 'str' |
| − | + | while(true); // infinite loop (to keep debugger running) | |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 346: | Line 511: | ||
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">strncat</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">void </span><span class="bigCodeBasic">&pToBuffer</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const void </span><span class="bigCodeBasic">&pFromBuffer</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const short </span><span class="bigCodeBasic">nMaxBufferSize</span><span class="bigCodePunc">)</span> | + | | class="functionType"| |
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigKeywordB">strncat</span> | ||
| + | <span class="bigCodePunc">(</span> | ||
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigCodeBasic">&pToBuffer</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const void </span> | ||
| + | <span class="bigCodeBasic">&pFromBuffer</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const short </span> | ||
| + | <span class="bigCodeBasic">nMaxBufferSize</span> | ||
| + | <span class="bigCodePunc">)</span> | ||
|- | |- | ||
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Function concatenates <span class="codeBasic">pFromBuffer</span> onto end of <span class="codeBasic">pToBuffer</span>. The variables are arrays of bytes terminated with a zero character. nMaxBufferSize is the maximum size of ‘pFromBuffer’ and is usually created with a <span class="keywordBI">sizeof</span><span class="codePunc">(</span><span class="codeBasic">..</span><span class="codePunc">)</span> function call. Identical to the function found in conventional C 'string.h' library file. | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Function concatenates <span class="codeBasic">pFromBuffer</span> onto end of <span class="codeBasic">pToBuffer</span>. The variables are arrays of bytes terminated with a zero character. nMaxBufferSize is the maximum size of ‘pFromBuffer’ and is usually created with a <span class="keywordBI">sizeof</span><span class="codePunc">(</span><span class="codeBasic">..</span><span class="codePunc">)</span> function call. Identical to the function found in conventional C 'string.h' library file. | ||
| Line 374: | Line 551: | ||
|- | |- | ||
|<syntaxhighlight lang="ROBOTC"> | |<syntaxhighlight lang="ROBOTC"> | ||
| − | string str1 = "ROBOT"; | + | string str1 = "ROBOT"; // String 'str1' is "ROBOT". |
| − | string str2 = "C!"; | + | string str2 = "C!"; // String 'str2' is "C!". |
| − | int copy_length = 1; | + | int copy_length = 1; // Int 'copy_length' is set to 1. |
| − | strncat(str1, str2, copy_length); | + | strncat(str1, str2, copy_length); /* Concatinate 'copy_length' amount of characters |
| − | + | from string 'str2' onto string 'str1'. */ | |
| − | + | while(true); // infinite loop (to keep debugger running) | |
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
| Line 393: | Line 570: | ||
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | class="functionType"| <span class="bigKeywordBI">short </span><span class="bigKeywordB">strncmp</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">void </span><span class="bigCodeBasic">&pString1</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const void </span><span class="bigCodeBasic">&pString2</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const short </span><span class="bigCodeBasic">nMaxBufferSize</span><span class="bigCodePunc">)</span> | + | | class="functionType"| |
| + | <span class="bigKeywordBI">short </span> | ||
| + | <span class="bigKeywordB">strncmp</span> | ||
| + | <span class="bigCodePunc">(</span> | ||
| + | <span class="bigKeywordBI">void </span> | ||
| + | <span class="bigCodeBasic">&pString1</span> | ||
| + | <span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const void </span> | ||
| + | <span class="bigCodeBasic">&pString2</span | ||
| + | ><span class="bigCodePunc">, </span> | ||
| + | <span class="bigKeywordBI">const short </span> | ||
| + | <span class="bigCodeBasic">nMaxBufferSize</span> | ||
| + | <span class="bigCodePunc">)</span> | ||
|- | |- | ||
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_short|short]]) Function compares <span class="codeBasic">pString1</span> with <span class="codeBasic">pString2</span>. Returns negative value if less than, 0 if equal and positive value if greater than. The variables are arrays of bytes terminated with a zero char. <span class="codeBasic">nMaxBufferSize</span> is the maximum number of bytes to compare and is usually created with a <span class="keywordBI">sizeof</span><span class="codePunc">(</span><span class="codeBasic">..</span><span class="codePunc">)</span> function call. Identical to the function found in conventional C 'string.h' | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_short|short]]) Function compares <span class="codeBasic">pString1</span> with <span class="codeBasic">pString2</span>. Returns negative value if less than, 0 if equal and positive value if greater than. The variables are arrays of bytes terminated with a zero char. <span class="codeBasic">nMaxBufferSize</span> is the maximum number of bytes to compare and is usually created with a <span class="keywordBI">sizeof</span><span class="codePunc">(</span><span class="codeBasic">..</span><span class="codePunc">)</span> function call. Identical to the function found in conventional C 'string.h' | ||
| Line 428: | Line 617: | ||
compare the first 4 chars of each string. */ | compare the first 4 chars of each string. */ | ||
| − | if(strncmp(str1, str2, cmp_chars) < 0) | + | if(strncmp(str1, str2, cmp_chars) < 0) // If 'str1' < 'str2' up to 4 chars: |
{ | { | ||
| − | + | // 'str1' is < 'str2' up to 4 chars. | |
} | } | ||
| − | else if(strncmp(str1, str2, cmp_chars) > 0) | + | else if(strncmp(str1, str2, cmp_chars) > 0) // If 'str1' > 'str2' up to 4 chars: |
{ | { | ||
| − | + | // 'str1' is > 'str2' up to 4 chars. | |
} | } | ||
| − | else | + | else // If 'str1' == 'str2' up to 4 chars: |
{ | { | ||
| − | + | // 'str1' is = 'str2' up to 4 chars. | |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 07:32, 21 May 2012
| For information about displaying on the NXT LCD, please see the article: NXT Display Functions.
For information about displaying on the VEX LCD, please see the article: Cortex Display Functions.
The number before the decimal is how many digits before the decimal you wish to display, while the number after the decimal is how many digits after the decimal you wish to display. So "%1.2f" tells us to display one digit before the decimal and two digits after the decimal, with "3.14" as the final result. |
|
| |||||||
sprintf
|
void sprintf ( string &sString , const string sFormatString , ... ) | |||||||||
| (void) This function writes the data from sFormatString to &sString. Identical to the function found in conventional C 'string.h' library. | |||||||||
| |||||||||
|
strcat
|
void strcat ( void &pToBuffer , const void &pFromBuffer ) | |||||||||
| (void) Function concatenates pFromBuffer onto end of pToBuffer. The variables are arrays of bytes terminated with zero character. It is user responsibility to ensure that the 'To' array is large enough to hold the result. ROBOTC is not able to do any range checking! Identical to the function found in conventional C 'string.h' library. | |||||||||
| |||||||||
|
strcmp
|
short strcmp ( void &pString1 , const void &pString2 ) | |||||||||
| (short) Function compares pString1 with pString2. Returns negative value if less than, 0 if equal and positive value if greater than. The variables are arrays of bytes terminated with a zero char. Identical to the function found in conventional C 'string.h' library. | |||||||||
| |||||||||
|
strcpy
|
void strcpy ( void &pToBuffer , const void &pFromBuffer ) | |||||||||
| (void) Function copies pFromBuffer to pToBuffer. The variables are arrays of bytes terminated with a zero character. It is user responsibility to ensure that the 'To' array is large enough to hold the result. ROBOTC is not able to do any range checking! Identical to the function found in conventional C 'string.h' library. | |||||||||
| |||||||||
|
StringDelete
|
void StringDelete ( string &sDest , const int nIndex , const int nSize ) | ||||||||||||
| (void) Deletes a substring from a string. | ||||||||||||
| ||||||||||||
|
StringFind
|
int StringFind ( const string &sSrce , const string &sSearch ) | |||||||||
| (int) Finds the position in a string of the selected substring. | |||||||||
| |||||||||
|
StringFormat
|
void StringFormat ( string &sDest , const string sFormatString , ... ) | |||||||||
| (void) Formats a string using the specified format-string. | |||||||||
| |||||||||
|
StringFromChars
|
void StringFromChars ( string &sToString , const char &FromChars ) | |||||||||
| (void) Converts an array of bytes to a string value. You MUST end your char array with a char value of zero! | |||||||||
| |||||||||
|
strncat
|
void strncat ( void &pToBuffer , const void &pFromBuffer , const short nMaxBufferSize ) | ||||||||||||
| (void) Function concatenates pFromBuffer onto end of pToBuffer. The variables are arrays of bytes terminated with a zero character. nMaxBufferSize is the maximum size of ‘pFromBuffer’ and is usually created with a sizeof(..) function call. Identical to the function found in conventional C 'string.h' library file. | ||||||||||||
| ||||||||||||
|
strncmp
|
short strncmp ( void &pString1 , const void &pString2, const short nMaxBufferSize ) | ||||||||||||
| (short) Function compares pString1 with pString2. Returns negative value if less than, 0 if equal and positive value if greater than. The variables are arrays of bytes terminated with a zero char. nMaxBufferSize is the maximum number of bytes to compare and is usually created with a sizeof(..) function call. Identical to the function found in conventional C 'string.h' | ||||||||||||
| ||||||||||||
|