Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSAttributedStringMBS class.

Next items

NSAttributedStringMBS.AsCFAttributedString 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 CFAttributedStringMBS object pointing to same attributed string.
Example
// make NS version
dim n as new NSAttributedStringMBS

if n.initWithString("Hello World") then
// convert
dim c as CFAttributedStringMBS = n.AsCFAttributedString

// and check content
MsgBox c.String
end if

For passing to functions which need a CFAttributedStringMBS.

Some examples using this method:

NSAttributedStringMBS.attributeAtIndex(name as string, location as UInt64) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.

name: The name of an attribute.
location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
effectiveRange: Optional. If the named attribute exists at index, upon return aRange contains a range over which the named attribute's value applies. If the named attribute does not exist at index, upon return aRange contains the range over which the attribute does not exist.
The range isn't necessarily the maximum range covered by attributeName, and its extent is implementation-dependent. If you need the maximum range, use the other variant of this method.

Returns the value for the attribute named attributeName of the character at index index, or nil if there is no such attribute.
Raises an NSRangeException if index lies beyond the end of the receiver's characters.

For information about where to find the attribute keys for the returned dictionary, see the overview section of this document.

See also:

Some examples using this method:

NSAttributedStringMBS.attributeAtIndex(name as string, location as UInt64, inRange as NSRangeMBS) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the value for the attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.

name: The name of an attribute.
location: The index at which to test for attributeName.
longestEffectiveRange: Optional. If the named attribute exists at index, upon return aRange contains the full range over which the value of the named attribute is the same as that at index, clipped to rangeLimit. If the named attribute does not exist at index, upon return aRange contains the full range over which the attribute does not exist, clipped to rangeLimit.
inRange: The range over which to search for continuous presence of attributeName. This value must not exceed the bounds of the receiver.

Returns the value for the attribute named attributeName of the character at index, or nil if there is no such attribute.

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

If you don't need the longest effective range, it's far more efficient to use the other variant method to retrieve the attribute value.

For information about where to find the attribute keys for the returned dictionary, see the overview section of this document.

See also:

NSAttributedStringMBS.attributeAtIndex2(name as string, location as UInt64, byref effectiveRange as NSRangeMBS) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.
Example

// list all links
Dim n As NSAttributedStringMBS = TextArea1.NSTextViewMBS.textStorage

Dim pos As Integer = 0
Dim Len As Integer = n.Length
Dim effectiveRange As NSRangeMBS

While pos < Len

Dim v As Variant = n.attributeAtIndex2(n.NSLinkAttributeName, pos, effectiveRange)

If v <> Nil Then
Dim url As String = v
Listbox1.AddRow url
End If

pos = pos + effectiveRange.Length

Wend

name: The name of an attribute.
location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
effectiveRange: Optional. If the named attribute exists at index, upon return aRange contains a range over which the named attribute's value applies. If the named attribute does not exist at index, upon return aRange contains the range over which the attribute does not exist.
The range isn't necessarily the maximum range covered by attributeName, and its extent is implementation-dependent. If you need the maximum range, use the other variant of this method.

Returns the value for the attribute named attributeName of the character at index index, or nil if there is no such attribute.
Raises an NSRangeException if index lies beyond the end of the receiver's characters.

For information about where to find the attribute keys for the returned dictionary, see the overview section of this document.

See also:

NSAttributedStringMBS.attributeAtIndex2(name as string, location as UInt64, byref longestEffectiveRange as NSRangeMBS, inRange as NSRangeMBS) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the value for the attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.

name: The name of an attribute.
location: The index at which to test for attributeName.
longestEffectiveRange: Optional. If the named attribute exists at index, upon return aRange contains the full range over which the value of the named attribute is the same as that at index, clipped to rangeLimit. If the named attribute does not exist at index, upon return aRange contains the full range over which the attribute does not exist, clipped to rangeLimit.
inRange: The range over which to search for continuous presence of attributeName. This value must not exceed the bounds of the receiver.

Returns the value for the attribute named attributeName of the character at index, or nil if there is no such attribute.

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

If you don't need the longest effective range, it's far more efficient to use the other variant method to retrieve the attribute value.

For information about where to find the attribute keys for the returned dictionary, see the overview section of this document.

See also:

NSAttributedStringMBS.attributedSubstringFromRange(range as NSRangeMBS) as NSAttributedStringMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns an NSAttributedString object consisting of the characters and attributes within a given range in the receiver.

Range: The range from which to create a new attributed string. aRange must lie within the bounds of the receiver.

Returns an NSAttributedString object consisting of the characters and attributes within aRange in the receiver.

Raises an NSRangeException if any part of aRange lies beyond the end of the receiver's characters. This method treats the length of the string as a valid range value that returns an empty string.

NSAttributedStringMBS.attributesAtIndex(location as UInt64) as dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the attributes for the character at a given index.

location: The index for which to return attributes. This value must lie within the bounds of the receiver.
Range: Optional. Upon return, the range over which the attributes and values are the same as those at index. This range isn't necessarily the maximum range covered, and its extent is implementation-dependent. If you need the maximum range, use other variant of this method.

Returns the attributes for the character at index.
Raises an NSRangeException if index lies beyond the end of the receiver's characters.

See also:

Some examples using this method:

NSAttributedStringMBS.attributesAtIndex(location as UInt64, inRange as NSRangeMBS) as dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the attributes for the character at a given index, and by reference the range over which the attributes apply.

location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
range: Optional. Upon return contains the maximum range over which the attributes and values are the same as those at index, clipped to range Limit.
inRange: The range over which to search for continuous presence of the attributes at index. This value must not exceed the bounds of the receiver.

Raises an NSRangeException if index or any part of rangeLimit lies beyond the end of the receiver's characters.
If you don't need the range information, it's far more efficient to use the other variant of this method to retrieve the attribute value.

For information about where to find the attribute keys for the returned dictionary, see the overview section of this document.

See also:

NSAttributedStringMBS.attributesAtIndex2(location as UInt64, byref range as NSRangeMBS) as dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the attributes for the character at a given index.

location: The index for which to return attributes. This value must lie within the bounds of the receiver.
Range: Optional. Upon return, the range over which the attributes and values are the same as those at index. This range isn't necessarily the maximum range covered, and its extent is implementation-dependent. If you need the maximum range, use other variant of this method.

Returns the attributes for the character at index.
Raises an NSRangeException if index lies beyond the end of the receiver's characters.

See also:

NSAttributedStringMBS.attributesAtIndex2(location as UInt64, byref range as NSRangeMBS, inRange as NSRangeMBS) as dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 12.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the attributes for the character at a given index, and by reference the range over which the attributes apply.

location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
range: Optional. Upon return contains the maximum range over which the attributes and values are the same as those at index, clipped to range Limit.
inRange: The range over which to search for continuous presence of the attributes at index. This value must not exceed the bounds of the receiver.

Raises an NSRangeException if index or any part of rangeLimit lies beyond the end of the receiver's characters.
If you don't need the range information, it's far more efficient to use the other variant of this method to retrieve the attribute value.

For information about where to find the attribute keys for the returned dictionary, see the overview section of this document.

See also:

NSAttributedStringMBS.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 attributed string.

NSAttributedStringMBS.Convert_Operator as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 18.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Converts to string by just returning string part.

NSAttributedStringMBS.copy as NSAttributedStringMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 9.6 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a copy of the attributed string.

NSAttributedStringMBS.CopyToClipboard as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 18.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Copies styled text to clipboard.

NSAttributedStringMBS.dataFromRange(offset as Integer, length as Integer, documentAttributes as dictionary = nil, byref error as NSErrorMBS) as memoryblock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns an data object that contains a text stream 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.
error: An in-out variable containing an encountered error, if any.

Returns the data for the attributed string, or nil if failure. When nil, error encapsulates the error information.
Raises an NSRangeException if any part of range lies beyond the end of the receiver’s characters.

NSAttributedStringMBS.docFormatFromRange(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 ❌ No Desktop, Console & Web
Creates DOC data from the whole string.

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

See also:

Some examples using this method:

NSAttributedStringMBS.docFormatFromRange(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 ❌ No Desktop, Console & Web
Creates DOC 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.fileWrapperFromRange(offset as Integer, length as Integer, documentAttributes as dictionary = nil, byref Error as NSErrorMBS) as NSFileWrapperMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns an NSFileWrapper object that contains a text stream corresponding to the characters and attributes within the given range.
Example
// get styled text from htmlviewer
dim w as WebViewMBS = HTMLViewer1.WebViewMBS
dim f as WebFrameMBS = w.mainFrame
dim v as WebFrameViewMBS = f.frameView
dim d as WebDocumentViewMBS = v.documentView
dim n as NSAttributedStringMBS = d.attributedString


// package it
dim da as new Dictionary
da.Value(n.NSDocumentTypeDocumentAttribute) = n.NSRTFDTextDocumentType

dim e as NSErrorMBS
dim fw as NSFileWrapperMBS = n.fileWrapperFromRange(0, n.Length, da, e)
if e <> nil then
MsgBox e.LocalizedDescription
Return
end if

// write to disk
dim file as FolderItem = SpecialFolder.Desktop.Child("test.rtfd")
if fw.writeToFile(file, e) then
MsgBox "OK"
else
MsgBox e.LocalizedDescription
end if

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.
error: An in-out variable containing an encountered error, if any.

Returns a file wrapper for the appropriate document type, or nil if failure. When nil, error encapsulates the error information.

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

NSAttributedStringMBS.GeneratePDF(PrintOptions as Variant = nil) as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 16.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Creates a PDF for attributed string.
Example
// read file
dim fi as FolderItem = SpecialFolder.Desktop.Child("test.docx")

dim d as new Dictionary
dim n as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithPath(fi, d)

// write pdf
dim p as MemoryBlock = n.GeneratePDF(nil)

dim fo as FolderItem = SpecialFolder.Desktop.Child("test.pdf")
dim bo as BinaryStream = BinaryStream.Create(fo)
bo.Write p

PrintOptions is optional NSPrintInfoMBS object for print settings like margin.

NSAttributedStringMBS.htmlString as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 7.8 ✅ Yes ❌ No ❌ No ✅ Yes All
A self made function to return the text content as html string preserving the style information.
Example
dim s as NSAttributedStringMBS

s=new NSAttributedStringMBS

if s.initwithhtml("<b>Hello</b>") then
MsgBox s.htmlstring // shows "<b>Hello</b>"
MsgBox s.text // shows "Hello"
end if

Does not always work well, but can help.
(Apple has no official function for this)

Some examples using this method:

NSAttributedStringMBS.initWithAttributedString(text 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
Initializes string with content of the given attributed string.

Returns true on success.

NSAttributedStringMBS.initWithDocFormat(data as MemoryBlock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Text MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Initializes string with content of given DOC file data.

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

See also:

NSAttributedStringMBS.initWithDocFormat(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 ❌ No Desktop, Console & Web
Initializes string with content of given DOC file data.

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

See also:

NSAttributedStringMBS.initWithHTML(data as MemoryBlock) 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 HTML file data.
Example
dim n as NSAttributedStringMBS
n=new NSAttributedStringMBS
if n.initWithHTML("<b>test</b>") then
MsgBox n.text
else
MsgBox "failed"
end if

dim attribText as new NSAttributedStringMBS
dim text as string = "<P>Hello öäü</P>"

text = ConvertEncoding(text, encodings.ISOLatin1)

If attribText.initWithHTML(text) Then
MsgBox attribText.text
End If

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

With plugin version 9.4 this uses the system function to parse html. The old plugin function is available with the name initWithHTMLOld.

On Mac OS X 10.6 the text encoding expected is ISO Latin 1 as far as I see.

See also:

NSAttributedStringMBS.initWithHTML(data as MemoryBlock, BaseURL 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 the object with html code from a given url.
Example
dim n as NSAttributedStringMBS
n=new NSAttributedStringMBS
if n.initWithHTML("<b>test</b>","http://www.apple.com") then
MsgBox n.text
else
MsgBox "failed"
end if

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

See also:

NSAttributedStringMBS.initWithHTML(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 HTML file data.

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

With plugin version 9.4 this uses the system function to parse html. The old plugin function is available with the name initWithHTMLOld.

On Mac OS X 10.6 the text encoding expected is ISO Latin 1 as far as I see.

See also:

NSAttributedStringMBS.initWithHTML(data as memoryblock, options as Dictionary, byref documentAttributes as dictionary) as boolean

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

Dim theBody As String = "<html><body>Test äöü</body></html>"

Dim documentAttributes As Dictionary
Dim documentOptions As New Dictionary

// define the text encoding
Const NSUTF8StringEncoding = 4
documentOptions.Value(NSAttributedStringMBS.NSCharacterEncodingDocumentOption) = NSUTF8StringEncoding
// and a default base URL for finding images
documentOptions.Value(NSAttributedStringMBS.NSBaseURLDocumentOption) = NSURLMBS.URLWithString("https://monkeybreadsoftware.de/")
// and a timeout for network queries
documentOptions.Value(NSAttributedStringMBS.NSTimeoutDocumentOption) = 30

Dim BodyAttributed As New NSAttributedStringMBS
If BodyAttributed.initWithHTML(theBody, documentOptions, documentAttributes) Then
MessageBox BodyAttributed.Text
Else
Break // failed?
End If

Returns true on success.
options: Put in some options for parsing the document like NSCharacterEncodingDocumentOption or NSTextEncodingNameDocumentOption.
documentAttributes: Optional dictionary to receive the attributes.

See also:

NSAttributedStringMBS.initWithHTMLOld(data as string) as boolean

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

With plugin version 9.4 the initWithHTML method uses the system function to parse html. The old plugin function is available with the name initWithHTMLOld.

NSAttributedStringMBS.initWithPath(file as folderitem) as boolean

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

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

See also:

NSAttributedStringMBS.initWithPath(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.

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

See also:

NSAttributedStringMBS.initWithPath(path as string) as boolean

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

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

See also:

NSAttributedStringMBS.initWithPath(path 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 path string.

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

See also:

NSAttributedStringMBS.initWithRTF(data as MemoryBlock) 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 RTF file data.

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

See also:

Some examples using this method:

NSAttributedStringMBS.initWithRTF(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 RTF file data.

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

See also:

NSAttributedStringMBS.initWithRTFD(data as MemoryBlock) 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 RTFD file data.

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

See also:

Next items

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


The biggest plugin in space...