Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSAttributedStringMBS class.

Previous items

NSAttributedStringMBS.initWithRTFD(data as memoryblock, byref documentAttributes as dictionary) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes string with content of given RTFD file data.

documentAttributes: Optional dictionary to receive the attributes.
Returns true on success.

See also:

NSAttributedStringMBS.initWithString(text as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes string with content of given plain text.
Example
dim n as NSAttributedStringMBS
n=new NSAttributedStringMBS
if n.initWithHTML("test") then
MsgBox n.text
else
MsgBox "failed"
end if

documentAttributes: Optional dictionary to receive the attributes.
Returns true on success.

See also:

NSAttributedStringMBS.initWithString(text as string, withAttributes as Dictionary) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes string with content of given plain text.
Example
dim n as NSAttributedStringMBS
n=new NSAttributedStringMBS
if n.initWithHTML("test") then
MsgBox n.text
else
MsgBox "failed"
end if

documentAttributes: Optional dictionary to receive the attributes.
Returns true on success.

See also:

NSAttributedStringMBS.initWithURL(file as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes string with content of file at the given file.
Example
dim n as NSAttributedStringMBS
n=new NSAttributedStringMBS
if n.initWithURL(SpecialFolder.Desktop.Child("testfile")) then
MsgBox n.text
else
MsgBox "failed"
end if

documentAttributes: Optional dictionary to receive the attributes.
Returns true on success.

See also:

NSAttributedStringMBS.initWithURL(file as folderitem, byref documentAttributes as dictionary) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes string with content of file at the given file.
Example
dim n as NSAttributedStringMBS
dim documentAttributes as dictionary
n=new NSAttributedStringMBS
if n.initWithURL(SpecialFolder.Desktop.Child("testfile"), documentAttributes) then
MsgBox n.text
else
MsgBox "failed"
end if

documentAttributes: Optional dictionary to receive the attributes.
Returns true on success.

See also:

NSAttributedStringMBS.initWithURL(url as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes string with content of file at the given url.

documentAttributes: Optional dictionary to receive the attributes.
Returns true on success.

See also:

NSAttributedStringMBS.initWithURL(url as string, byref documentAttributes as dictionary) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes string with content of file at the given url.

documentAttributes: Optional dictionary to receive the attributes.
Returns true on success.

See also:

NSAttributedStringMBS.isEqualToAttributedString(other as NSAttributedStringMBS) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Compares both strings.
Example
dim n as NSAttributedStringMBS
dim m as NSAttributedStringMBS

n=new NSAttributedStringMBS
if n.initWithString("test") then
MsgBox n.text
else
MsgBox "failed"
end if

m=new NSAttributedStringMBS
if m.initWithString("test") then
MsgBox n.text
else
MsgBox "failed"
end if

if m.isEqualToAttributedString(n) then
MsgBox "Ok"
else
MsgBox "failed"
end if

m=new NSAttributedStringMBS
if m.initWithString("test2") then
MsgBox n.text
else
MsgBox "failed"
end if

if m.isEqualToAttributedString(n) then
MsgBox "failed"
else
MsgBox "Ok"
end if

Returns true if they are equal in content.

NSAttributedStringMBS.itemNumberInTextList(list as NSTextListMBS, location as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 18.1 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns the index of the item at the given location within the list.

list: The text list.
location: The location of the item.

Returns the index within the list.

NSAttributedStringMBS.lineRangeForRange(range as NSRangeMBS) as NSRangeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 18.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the range of characters representing the line or lines containing a given range.

Range: A range within the receiver. The value must not exceed the bounds of the receiver.

The range of characters representing the line or lines containing aRange, including the line termination characters.

NSAttributedStringMBS.mutableCopy as NSMutableAttributedStringMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 9.6 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a mutable copy of the 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

NSAttributedStringMBS.paragraphRangeForRange(range as NSRangeMBS) as NSRangeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 18.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the range of characters representing the paragraph or paragraphs containing a given range.

Range: A range within the receiver. The range must not exceed the bounds of the receiver.

The range of characters representing the paragraph or paragraphs containing range, including the paragraph termination characters.

A paragraph is any segment of text delimited by a carriage return (U+000D), newline (U+000A), or paragraph separator (U+2029).

NSAttributedStringMBS.rangeOfTextBlock(textBlock as NSTextBlockMBS, location as Integer) as NSRangeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 22.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns the range of the individual text block that contains the specified location.

NSAttributedStringMBS.rangeOfTextList(list as NSTextListMBS, location as Integer) as NSRangeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 18.1 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns the range of the given text list that contains the given location.

list: The text list.
location: The location in the text list.

Returns the range of the given text list containing the location.

NSAttributedStringMBS.rangeOfTextTable(textTable as NSTextTableMBS, location as Integer) as NSRangeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 22.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns the range of the specified text table that contains the specified location.

NSAttributedStringMBS.rtf as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 9.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the content of this attributed string as a RTF string.
Example
dim s as NSAttributedStringMBS

s=new NSAttributedStringMBS

if s.initWithString("Hello") then
MsgBox s.RTF
end if

// shows this text:
// {\rtf1\ansi\ansicpg1252\cocoartf949
// {\fonttbl\f0\fswiss\fcharset0 Helvetica;}
// {\colortbl;\red255\green255\blue255;}
// \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural
//
// \f0\fs24 \cf0 Hello}

Same as RTFFromRange(0,length)

NSAttributedStringMBS.RTFDFileWrapperFromRange(offset as Integer, length as Integer, documentAttributes as dictionary = nil) as NSFileWrapperMBS

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 an NSFileWrapper object that contains an RTFD document corresponding to the characters and attributes within the given range.

offset and length: The range.
documentAttributes: A required dictionary specifying the document attributes. The dictionary contains values from Document Types and must at least contain NSDocumentTypeDocumentAttribute. If there are no document-level attributes, dict can be nil.

Returns a file wrapper containing the RTFD data.

The file wrapper also includes the document-level attributes in docAttributes, as explained in RTF Files and Attributed Strings.
Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.
You can save the file wrapper using the NSFileWrapper method writeToFile.

NSAttributedStringMBS.RTFDFromRange(documentAttributes as dictionary = nil) as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 9.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates RTFD data from the current string range.

Returns nil on failure.
Same as RTFDFromRange(0,length)
documentAttributes can optionally be a dictionary with document attributes like author or title.

See also:

NSAttributedStringMBS.RTFDFromRange(offset as Integer, length as Integer, documentAttributes as dictionary = nil) as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates RTFD data from the current string range.

Returns nil on failure.
documentAttributes can optionally be a dictionary with document attributes like author or title.

See also:

NSAttributedStringMBS.RTFFromRange(documentAttributes as dictionary = nil) as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates RTF data from whole string.

Returns nil on failure.
Same as RTFFromRange(0,length)
documentAttributes can optionally be a dictionary with document attributes like author or title.

See also:

NSAttributedStringMBS.RTFFromRange(offset as Integer, length as Integer, documentAttributes as dictionary = nil) as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates RTF data from the current string range.
Example
// get some attributed text:
dim t as new NSAttributedStringMBS
call t.initWithString("Hello World")

// set document attributes
dim dic as new Dictionary
dic.Value(t.NSBottomMarginDocumentAttribute) = 20
dic.Value(t.NSLeftMarginDocumentAttribute) = 20
dic.Value(t.NSRightMarginDocumentAttribute) = 20
dic.Value(t.NSTopMarginDocumentAttribute) = 20
dic.Value(t.NSAuthorDocumentAttribute) = "Test User"

// get rtf
dim rtf as string = t.RTFFromRange(dic)

// write to file
dim f as FolderItem = SpecialFolder.Desktop.Child("test.rtf")
dim b as BinaryStream = BinaryStream.Create(f, true)
b.Write rtf

Returns nil on failure.
documentAttributes can optionally be a dictionary with document attributes like author or title.

See also:

Previous items

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


The biggest plugin in space...