Class DText

Inherits from:
Object
Conforms to:
DComparable, DDatable, DParsable, DSizeable, DTextReadable, DTextScannable, DTextWritable, DTextable
Declared in:
DText.h

Class Hierarchy

    Object
      |
      +---DText

Class Description

The text string class implements methods for storing and manipulating text strings.

Example:
#include <stdio.h>
#include "ofc/DText.h"

int main(int argc, char *argv[])
{
  DText *str1 = [DText alloc];
  DText *str2 = [DText new  ];
  DText *str3 = [DText new  ];
  DText *str4 = [DText new  ];
  DText *str5 = [DText new  ];

                                       // String setters
  [str1 init :"  Initial  "];          // Init with a c-string

  [str2 format :"Form%ctted", 'a'];    // Set the string with a format

  [str3 set :"hello, this is a nice day"]; // Set the string

  [str4 set :"Substring" :2 :4];       // Set with substring

  [str5 set :'-' :15];                 // Make a string with 15 dashes

  printf("String setters: %s %s %s %s %s.\n",
      [str1 cstring], [str2 cstring], [str3 cstring], [str4 cstring], [str5 cstring]);

                                       // Character methods
  [str5 put :1 :'+'];                  // Put on index 1 a '+'

  printf("Last char in string1:%c.\n", [str1 get :-1]);

  [str5 delete :0];                    // Remove the first character from string5

                                       // Slice methods
  [str4 insert :1 :-1 :"string"];      // Replace st to string in string4

  [str5 insert :2 :4 :'+' :4];         // Replace [2,4] to ++++ in string5

  [str5 delete :6 :10];                // Remove a substring from string5

  printf ("String lengths: %ld %ld %ld %ld %ld.\n",
      [str1 length], [str2 length], [str3 length], [str4 length], [str5 length]);

                                       // String manipulation
  [str4 prepend :"Su"];                // Prepend to make Substring

  [str4 multiply :2];                  // Multiply substring twice

  [str3 capwords];                     // Capitalize all words in string3

  [str1 lower];                        // Lower all caps in string1

  [str1 strip];                        // Strip all leading and trailing spaces

  [str2 rjust :15];                    // Right justify string2

                                       // Results
  printf("Results: %s %s %s %s %s.\n",
      [str1 cstring], [str2 cstring], [str3 cstring], [str4 cstring], [str5 cstring]);

                                       // String compare
  if ([str1 compare :str4] == 0)
    printf("String1 and string4 are equal.\n");
  else
    if ([str1 compare :str4] < 0)
      printf("String1 is smaller than string4.\n");
    else
      printf("String1 is bigger than string4.\n");

  return 0;
}
Last modified:
05-Aug-2008 (DText.h)

Instance Variables

private unsigned long _size
the allocated size for the string
private unsigned _extra
the extra amount for sizing
private unsigned long _length
the length of the string
private unsigned long _pntr
the pointer for the DTextReadable,-Writable protocols
private char *_string
the string data
private int _error
the last error (or 0)

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0