---
name: "Text"
section: "3"
platform: "linux"
package: "objc-poc"
version: "3.1.3-2"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/Text"
---

# Text(3)

## Text

**Inherits from:**

Object

**Maturity Index:**

Experimental

## Class Description

The  **Text** class associates to a  **String** instance a  **RunArray** .  The runs for a string, consist of string segments that have the same text attributes, such as font, boldface, fontsize etc.

## Method types

**Creation**

\* new\
 \* new:\
 \* str:\
 \* sprintf:\
 \* fromString:\
 \* string:attribute:\
 \* copy\
 \* free

**Comparison**

\* hash\
 \* isEqual:

**Accessing**

\* string\
 \* runs\
 \* str\
 \* size\
 \* charAt:\
 \* charAt:put:\
 \* at:insert:\
 \* at:insert:count:\
 \* deleteFrom:to:\
 \* concat:\
 \* concatSTR:

**Emphasis**

\* allBold\
 \* makeBoldFrom:to:\
 \* addAttribute:\
 \* addAttribute:from:to:\
 \* attributesAt:\
 \* runLengthFor:

**Format Conversions**

\* asString\
 \* asText\
 \* asParagraph

**Printing**

\* printOn:

## Methods

new

\+ **new**

Creates an instance whose value is set to the empty string.

new:

\+ **new** :(unsigned) *nChars*

Creates an instance whose value is set to the empty string, can hold at least  *nChars* without having to expand.

str:

\+ **str** :(STR) *aString*

Creates an instance whose value is set to a copy of  *aString* .  If  *aString* is NULL, creates an instance whose value is set to the empty string.

sprintf:

\+ **sprintf** :(STR) *format,...*

Returns a new instace initialized just as the standard C library  *sprintf()* .  See the documentation on  *sprintf()* for the formats and variable declarations.

fromString:

\+ **fromString** : *aString*

Creates an instance whose value is set to  *aString* .

string:attribute:

\+ **string** : *aString* **attribute** : *attrib*

Creates an instance whose value is set to  *aString* and then sends itself an  **addAttribute:** message.

copy

\- **copy**

Returns a copy of the receiver with its internal C string copied as well.

free

\- **free**

Frees the receiver and its internal C string as well.

hash

\- ( unsigned ) **hash**

Returns a hash value based upon the contents of the string held in the receiver.

isEqual:

\- ( BOOL ) **isEqual** : *aStr*

Returns YES if the string and runarray contained by  *aStr* is equal to the contents of the receiver.

string

\- **string**

Returns the String instance for this Text object.

runs

\- **runs**

Returns the RunArray instance for this Text object.

str

\- ( STR ) **str**

Returns a pointer to the NULL-terminated C string stored in the receiver.

size

\- ( unsigned ) **size**

Returns the size of the String instance for this Text object.  The following all return the same value :

\[text size\];\
 \[\[text string\] size\];\
 \[\[text runs\] size\];\

charAt:

\- ( char ) **charAt** :(unsigned) *anOffset*

Returns the character at  *anOffset* or  **zero** if  *anOffset* is greater than the length of the C string.

charAt:put:

\- ( char ) **charAt** :(unsigned) *anOffset* **put** :(char) *aChar*

Replaces the character at  *anOffset* with  *aChar* and returns the old character which was in that location.  Returns  **zero** if  *anOffset* is greater than the length of the C string.

at:insert:

\- **at** :(unsigned) *anOffset* **insert** : *aString*

at:insert:count:

\- **at** :(unsigned) *anOffset* **insert** :(char\*) *aString* **count** :(int) *size*

deleteFrom:to:

\- **deleteFrom** :(unsigned) *p* **to** :(unsigned) *q*

concat:

\- **concat** : *b*

concatSTR:

\- **concatSTR** :(STR) *b*

allBold

\- **allBold**

This message is equivalent to,

\[self makeBoldFrom:0 to:\[self size\] - 1\].\

Returns  **self** (the text object).

makeBoldFrom:to:

\- **makeBoldFrom** :(unsigned) *p* **to** :(unsigned) *q*

Adds a boldface  **TextAttribute** for the characters from index  *p* to  *q* (including the characters at offset  *p* and  *q* ).  A boldface attribute has  **emphasiscode** equal to 1.

addAttribute:

\- **addAttribute** : *attribute*

This message is equivalent to,

\[self addAttribute:attribute from:0 to:\[self size\] - 1\].\

Returns  **self** (the text object).

addAttribute:from:to:

\- **addAttribute** : *attribute* **from** :(unsigned) *p* **to** :(unsigned) *q*

Adds  *attribute* to the string segments between  *p* and  *q* .

attributesAt:

\- **attributesAt** :(unsigned) *i*

Returns an  **OrdCltn** of TextAttribute instances for the character at index  *i* .

runLengthFor:

\- ( unsigned ) **runLengthFor** :(unsigned) *i*

Returns the number of remaining characters in the string segment to which the character at position  *i* belongs.  If  *i* is the first character of a run, this method returns the size of the run.  Otherwise it returns the size minus the index of character in the run.

asString

\- **asString**

Equivalent to  **string** .

asText

\- **asText**

Returns the object itself.

asParagraph

\- **asParagraph**

Returns a paragraph for this text object.

printOn:

\- **printOn** :(IOD) *aFile*

Prints the Text for the string contained by this instance.  Returns the receiver.
