Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSMutableAttributedStringMBS class.

NSMutableAttributedStringMBS.addAttribute(name as string, value as Variant, range as NSRangeMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Adds an attribute with the given name and value to the characters in the specified range.
Example
// create Hello World in red
dim a as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithString("Hello World")
dim m as NSMutableAttributedStringMBS = a.mutableCopy

m.addAttribute(a.NSForegroundColorAttributeName, NSColorMBS.redColor, new NSRangeMBS(0, m.length))

// put it in a textarea
TextArea1.NSTextViewMBS.textStorage.setAttributedString m

name: A string specifying the attribute name. Attribute keys can be supplied by another framework or can be custom ones you define. For information about where to find the system-supplied attribute keys, see the overview section in NSAttributedString Class Reference.
value: The attribute value associated with name.
Range: The range of characters to which the specified attribute/value pair applies.

You may assign any name/value pair you wish to a range of characters, in addition to the standard attributes described in the "Constants" section of NSAttributedString Additions. Raises an NSInvalidArgumentException if name or value is nil and an NSRangeException if any part of range lies beyond the end of the receiver's characters.

Plugin version 16.0 or newer ignores calls here with value = nil or empty name to avoid exceptions.

Some examples using this method:

NSMutableAttributedStringMBS.addAttributes(attrs as Dictionary, range as NSRangeMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Adds the given collection of attributes to the characters in the specified range.
Example
TextArea1.Text = "Hello"

Dim tv As NSTextViewMBS = TextArea1.NSTextViewMBS
Dim ts As NSTextStorageMBS = tv.TextStorage

Dim value As Color = &cFF0000

Dim offset As Integer = 0
Dim length As Integer = 5

Dim range As NSRangeMBS = NSMakeRangeMBS( offset, length )
ts.AddAttribute( NSAttributedStringMBS.NSForegroundColorAttributeName, value, range )

attributes: A dictionary containing the attributes to add. Attribute keys can be supplied by another framework or can be custom ones you define. For information about where to find the system-supplied attribute keys, see the overview section in NSAttributedString Class Reference.
Range: The range of characters to which the specified attributes apply.

You may assign any name/value pair you wish to a range of characters, in addition to the standard attributes described in the "Constants" section of NSAttributedString Additions. Raises an NSInvalidArgumentException if attributes is nil and an NSRangeException if any part of range lies beyond the end of the receiver's characters.

NSMutableAttributedStringMBS.appendAttributedString(attrString as NSAttributedStringMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Adds the characters and attributes of a given attributed string to the end of the receiver.
Example
const NSWritingDirectionNatural       = -1   // Determines direction using the Unicode Bidi Algorithm rules P2 and P3
const NSWritingDirectionLeftToRight = 0 // Left to right writing direction
const NSWritingDirectionRightToLeft = 1 // Right to left writing direction

const NSTextWritingDirectionEmbedding = 0
const NSTextWritingDirectionOverride = 2

dim t as NSTextStorageMBS = TextArea1.NSTextViewMBS.textStorage

// get hello in arabic
dim a as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithString("مرحبا")
dim m as NSMutableAttributedStringMBS = a.mutableCopy

// now set attributes for right to left
m.addAttribute t.NSWritingDirectionAttributeName, array(NSWritingDirectionRightToLeft+NSTextWritingDirectionOverride), new NSRangeMBS(0,m.Length)

// and add to textarea
t.appendAttributedString m

attributedString: The string whose characters and attributes are added.

Some examples using this method:

NSMutableAttributedStringMBS.appendString(attrString as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 18.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Adds the text to the end of the receiver.

NSMutableAttributedStringMBS.applyFontTraits(FontTraitMask as Integer, offset as Integer, length as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Applies the font attributes specified by mask to the characters in a range.

See the NSFontManager class specification for a description of the font traits available. Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

NSMutableAttributedStringMBS.AsCFMutableAttributedString as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 14.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new CFMutableAttributedStringMBS object pointing to same mutable attributed string.
Example
// make NS version
dim n as new NSAttributedStringMBS

if n.initWithString("Hello World") then

dim m as NSMutableAttributedStringMBS = n.mutableCopy

// convert
dim c as CFMutableAttributedStringMBS = m.AsCFMutableAttributedString

// and check content
MsgBox c.String
end if

For passing to functions which need a CFMutableAttributedStringMBS.

NSMutableAttributedStringMBS.beginEditing

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 9.6 ✅ Yes ❌ No ❌ No ✅ Yes All
Overridden by subclasses to buffer or optimize a series of changes to the receiver's characters or attributes, until it receives a matching endEditing message, upon which it can consolidate changes and notify any observers that it has changed.

You can nest pairs of beginEditing and endEditing messages.

NSMutableAttributedStringMBS.Constructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 19.0 ✅ Yes ❌ No ❌ No ✅ Yes All
The constructor to create empty mutable attributed string.

NSMutableAttributedStringMBS.containsAttachmentsInRange(offset as Integer, length as Integer) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns true if the receiver contains a property configured (NSAttachmentAttributeName with NSAttachmentCharacter) in range.

NSMutableAttributedStringMBS.deleteCharactersInRange(range as NSRangeMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 9.6 ✅ Yes ❌ No ❌ No ✅ Yes All
Deletes the characters in the given range along with their associated attributes.

Raises an NSRangeException if any part of aRange lies beyond the end of the receiver's characters.

NSMutableAttributedStringMBS.endEditing

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 9.6 ✅ Yes ❌ No ❌ No ✅ Yes All
Overridden by subclasses to consolidate changes made since a previous beginEditing message and to notify any observers of the changes.

The NSMutableAttributedString implementation does nothing. NSTextStorage, for example, overrides this method to invoke fixAttributesInRange and to inform its NSLayoutManager objects that they need to re-lay the text.

NSMutableAttributedStringMBS.fixAttachmentAttributeInRange(offset as Integer, length as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Cleans up attachment attributes in a range, removing all attachment attributes assigned to characters other than NSAttachmentCharacter.

Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

NSMutableAttributedStringMBS.fixAttributesInRange(offset as Integer, length as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Invokes the other fix... methods, allowing you to clean up an attributed string with a single message.

Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

NSTextStorage subclasses that return YES from the fixesAttributesLazily method should avoid directly calling fixAttributesInRange: or else bracket such calls with beginEditing and endEditing messages.

NSMutableAttributedStringMBS.fixFontAttributeInRange(offset as Integer, length as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Fixes the font attribute in aRange, assigning default fonts to characters with illegal fonts for their scripts and otherwise correcting font attribute assignments.

For example, Kanji characters assigned a Latin font are reassigned an appropriate Kanji font. Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

NSMutableAttributedStringMBS.fixParagraphStyleAttributeInRange(offset as Integer, length as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Fixes the paragraph style attributes in a range, assigning the first paragraph style attribute value in each paragraph to all characters of the paragraph.

This method extends the range as needed to cover the last paragraph partially contained. A paragraph is delimited by any of these characters, the longest possible sequence being preferred to any shorter:

  • U+000D (\r or CR)
  • U+000A (\n or LF)
  • U+2029 (Unicode paragraph separator) \r\n, in that order (also known as CRLF)

Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

NSMutableAttributedStringMBS.fontAttributesInRange(offset as Integer, length as Integer) as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Attributes which should be copied/pasted with "copy font".

NSMutableAttributedStringMBS.insertAttributedString(attrString as NSAttributedStringMBS, location as UInt64)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Inserts the characters and attributes of the given attributed string into the receiver at the given index.

attributedString: The string whose characters and attributes are inserted.
index: The index at which the characters and attributes are inserted.

The new characters and attributes begin at the given index and the existing characters and attributes from the index to the end of the receiver are shifted by the length of the attributed string. Raises an NSRangeException if index lies beyond the end of the receiver's characters.

NSMutableAttributedStringMBS.insertString(attrString as String, location as UInt64)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 18.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Inserts the text into the receiver at the given index.

NSMutableAttributedStringMBS.removeAttribute(name as string, range as NSRangeMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Removes the named attribute from the characters in the specified range.

name: A string specifying the attribute name to remove. Attribute keys can be supplied by another framework or can be custom ones you define. For information about where to find the system-supplied attribute keys, see the overview section in NSAttributedString Class Reference.
Range: The range of characters from which the specified attribute is removed.

Raises an NSRangeException if any part of range lies beyond the end of the receiver's characters.

NSMutableAttributedStringMBS.replaceCharacters(search as String, text as String, Options as Integer = 1)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 24.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Searches and replaces text in a mutable attributed string.
Example
// make some mutable string
Dim s As New NSMutableAttributedStringMBS
s.setString "Hello World!"

// now do the replace
s.replaceCharacters("world", "everyone")

// and show result
MessageBox s.Text

Default options is for case insensitive search, but you can pass other options.
(see search flags in PDFDocumentMBS class)

NSMutableAttributedStringMBS.replaceCharactersInRange(range as NSRangeMBS, attrString as NSAttributedStringMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Replaces the characters and attributes in a given range with the characters and attributes of the given attributed string.

Range: The range of characters and attributes replaced.
attributedString: The attributed string whose characters and attributes replace those in the specified range.

Raises an NSRangeException if any part of range lies beyond the end of the receiver's characters.

See also:

NSMutableAttributedStringMBS.replaceCharactersInRange(range as NSRangeMBS, text as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Replaces the characters in the given range with the characters of the given string.

Range: A range specifying the characters to replace.
text: A string specifying the characters to replace those in range.

The new characters inherit the attributes of the first replaced character from range. Where the length of range is 0, the new characters inherit the attributes of the character preceding range if it has any, otherwise of the character following range.

Raises an NSRangeException if any part of range lies beyond the end of the receiver's characters.

See also:

NSMutableAttributedStringMBS.rulerAttributesInRange(offset as Integer, length as Integer) as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Attributes which should be copied/pasted with "copy ruler".

NSMutableAttributedStringMBS.setAlignment(alignment as Integer, offset as Integer, length as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Sets the alignment characteristic of the paragraph style attribute for the characters in aRange to alignment.

When attribute fixing takes place, this change will affect only paragraphs whose first character was included in aRange. Raises an NSRangeException if any part of a range lies beyond the end of the receiver’s characters.

NSMutableAttributedStringMBS.setAttributedString(attrString as NSAttributedStringMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Replaces the receiver's entire contents with the characters and attributes of the given attributed string.
Example
// create Hello World in red
dim a as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithString("Hello World")
dim m as NSMutableAttributedStringMBS = a.mutableCopy

m.addAttribute(a.NSForegroundColorAttributeName, NSColorMBS.redColor, new NSRangeMBS(0, m.length))

// put it in a textarea
TextArea1.NSTextViewMBS.textStorage.setAttributedString m

attributedString: The attributed string whose characters and attributes replace those in the receiver.

NSMutableAttributedStringMBS.setAttributes(attrs as Dictionary, range as NSRangeMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the attributes for the characters in the specified range to the specified attributes.

attributes: A dictionary containing the attributes to set. Attribute keys can be supplied by another framework or can be custom ones you define. For information about where to find the system-supplied attribute keys, see the overview section in NSAttributedString Class Reference.
Range: The range of characters whose attributes are set.

These new attributes replace any attributes previously associated with the characters in range. Raises an NSRangeException if any part of range lies beyond the end of the receiver's characters.

To set attributes for a zero-length NSMutableAttributedString displayed in a text view, use the NSTextView method setTypingAttributes.

NSMutableAttributedStringMBS.setBaseWritingDirection(writingDirection as Integer, offset as Integer, length as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Sets the base writing direction for the characters in range to writingDirection.

NSMutableAttributedStringMBS.setString(attrString as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 18.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Replaces the receiver's entire contents with the given string.

NSMutableAttributedStringMBS.subscriptRange(offset as Integer, length as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Decrements the value of the superscript attribute for characters in a range by 1.
Example
TextArea1.Text = "Hello World"

dim n as NSTextViewMBS = TextArea1.NSTextViewMBS
dim s as NSTextStorageMBS = n.textStorage

s.subscriptRange(6,5)

NSMutableAttributedStringMBS.superscriptRange(offset as Integer, length as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Increments the value of the superscript attribute for characters in a range by 1.

NSMutableAttributedStringMBS.unscriptRange(offset as Integer, length as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Removes the superscript attribute from the characters in a range.

NSMutableAttributedStringMBS.updateAttachmentsFromPath(file as folderitem)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 15.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Updates all attachments based on files contained in the RTFD file package at path.

See also:

NSMutableAttributedStringMBS.updateAttachmentsFromPath(path as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 15.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Updates all attachments based on files contained in the RTFD file package at path.

See also:

The items on this page are in the following plugins: MBS MacBase Plugin.


The biggest plugin in space...