Changeset f8913b7c for doc/theses/mike_brooks_MMath/string.tex
- Timestamp:
- Apr 1, 2025, 9:20:48 AM (6 months ago)
- Branches:
- master
- Children:
- ee70ff5
- Parents:
- 4223317
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/string.tex
r4223317 rf8913b7c 59 59 A \CFA string manages its length separately from the string, so there is no null (@'\0'@) terminating value at the end of a string value. 60 60 Hence, a \CFA string cannot be passed to a C string manipulation routine, such as @strcat@. 61 Like C strings, the characters in a @string@ are numbered starting from 0. 62 61 Like C strings, characters in a @string@ are numbered from the left starting at 0, and in \CFA numbered from the right starting at -1. 62 \begin{cquote} 63 \sf 64 \begin{tabular}{@{}rrrrrl@{}} 65 \small\tt a & \small\tt b & \small\tt c & \small\tt d & \small\tt e \\ 66 0 & 1 & 2 & 3 & 4 & left to right index \\ 67 -5 & -4 & -3 & -2 & -1 & right to left index 68 \end{tabular} 69 \end{cquote} 63 70 The following operations have been defined to manipulate an instance of type @string@. 64 71 The discussion assumes the following declarations and assignment statements are executed. … … 123 130 s = 'x'; 124 131 s = "abc"; 125 char cs[ 5] = "abc";132 char cs[] = "abc"; 126 133 s = cs; 127 134 // conversion of integral, floating-point, and complex to string … … 269 276 A negative length means that characters are selected in the opposite (right to left) direction from the starting position. 270 277 If the substring request extends beyond the beginning or end of the string, it is clipped (shortened) to the bounds of the string. 271 If the substring request is completely outside of the original string, a null string located at the end of the original string is returned. 272 273 The substring operation can also appear on the left hand side of the assignment operator. 274 The substring is replaced by the value on the right hand side of the assignment. 275 The length of the right-hand-side value may be shorter, the same length, or longer than the length of the substring that is selected on the left hand side of the assignment. 276 \begin{cfa} 277 digit( 3, 3 ) = ""; $\C{// digit is assigned "0156789"}$ 278 digit( 4, 3 ) = "xyz"; $\C{// digit is assigned "015xyz9"}$ 279 digit( 7, 0 ) = "***"; $\C{// digit is assigned "015xyz***9"}$ 280 digit(-4, 3 ) = "$\tt\$\$\$$"; $\C{// digit is assigned "015xyz\$\$\$9"}$ 281 \end{cfa} 278 If the substring request is completely outside of the original string, a null string is returned. 279 280 The substring operation can also appear on the left side of an assignment and replaced by the string value on the right side. 281 The length of the right string may be shorter, the same length, or longer than the length of left string. 282 Hence, the left string may decrease, stay the same, or increase in length. 283 \begin{cquote} 284 \setlength{\tabcolsep}{15pt} 285 \begin{tabular}{@{}l|l@{}} 286 \begin{cfa} 287 digit( 3, 3 ) = ""; 288 digit( 4, 3 ) = "xyz"; 289 digit( 7, 0 ) = "***"; 290 digit(-4, 3 ) = "$\tt\$\$\$$"; 291 \end{cfa} 292 & 293 \begin{cfa} 294 0126789 295 0126xyz 296 0126xyz 297 012$\$\$\$$z 298 \end{cfa} 299 \end{tabular} 300 \end{cquote} 282 301 A substring is treated as a pointer into the base (substringed) string rather than creating a copy of the subtext. 283 As with all pointers, if the item they are pointing at is changed, then the pointer is referring to the changed item.302 Hence, if the referenced item is changed, then the pointer sees the change. 284 303 Pointers to the result value of a substring operation are defined to always start at the same location in their base string as long as that starting location exists, independent of changes to themselves or the base string. 285 304 However, if the base string value changes, this may affect the values of one or more of the substrings to that base string. … … 315 334 \begin{cfa} 316 335 s = name( 2 ); $\C{// s is assigned "ETER"}$ 317 name( 2 ) = "IPER"; $\C{// name is assigned "PIPER"}$336 name( 2 ) = "IPER"; $\C{// name is assigned "PIPER"}$ 318 337 \end{cfa} 319 338 It is also possible to substring using a string as the index for selecting the substring portion of the string. … … 332 351 The @index@ operation 333 352 \begin{cfa} 334 int index( const string & key, int start = 1, occurrence occ = first );353 int index( const string & key, int start = 1, occurrence occ = first ); 335 354 \end{cfa} 336 355 returns the position of the first or last occurrence of the @key@ (depending on the occurrence indicator @occ@ that is either @first@ or @last@) in the current string starting the search at position @start@. … … 338 357 %If the @key@ has zero length, the value 1 is returned regardless of what the current string contains. 339 358 A negative starting position is a specification from the right end of the string. 340 \begin{cfa} 341 i = digit.index( "567" ); $\C{// i is assigned 3}$ 342 i = digit.index( "567", 7 ); $\C{// i is assigned 11}$ 343 i = digit.index( "567", -1, last ); $\C{// i is assigned 3}$ 344 i = name.index( "E", 5, last ); $\C{// i is assigned 4}$ 345 \end{cfa} 346 359 \begin{cquote} 360 \setlength{\tabcolsep}{15pt} 361 \begin{tabular}{@{}l|l@{}} 362 \begin{cfa} 363 i = find( digit, "567" ); 364 i = find( digit, "567", 7 ); 365 i = digit.index( "567", -1, last ); 366 i = name.index( "E", 5, last ); 367 \end{cfa} 368 & 369 \begin{cfa} 370 5 371 10 372 373 374 \end{cfa} 375 \end{tabular} 376 \end{cquote} 347 377 The next two string operations test a string to see if it is or is not composed completely of a particular class of characters. 348 378 For example, are the characters of a string all alphabetic or all numeric?
Note:
See TracChangeset
for help on using the changeset viewer.