Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

NSStringCompareMBS(s as string, t as string, options as Integer) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
global method Cocoa MBS Main Plugin 8.6 Yes No No Yes, macOS only No
Function: Compares two things using the Cocoa string functions.
// constants for the function:
const NSCaseInsensitiveSearch = 1
const NSLiteralSearch = 2
const NSBackwardsSearch = 4
const NSAnchoredSearch = 8
const NSNumericSearch = 64
const NSDiacriticInsensitiveSearch = 128
const NSWidthInsensitiveSearch = 256
const NSForcedOrderingSearch = 512

const NSOrderedAscending = -1
const NSOrderedSame = 0
const NSOrderedDescending = 1

if NSStringCompareMBS("Hello","hello", NSCaseInsensitiveSearch)=0 then
msgbox "equal (correct)"
msgbox "not equal"
end if

if NSStringCompareMBS("Hello","hello", 0)=0 then
msgbox "equal"
msgbox "not equal (correct)"
end if

if NSStringCompareMBS("Hello","Hellö", NSDiacriticInsensitiveSearch)=0 then
msgbox "equal (correct)"
msgbox "not equal"
end if
Following constants can be used for the compare:

NSCaseInsensitiveSearch1Case Insensitive
NSLiteralSearch2Exact character-by-character equivalence
NSBackwardsSearch4Search from end of source string
NSAnchoredSearch8Search is limited to start (or end, if NSBackwardsSearch) of source string
NSNumericSearch64Added in 10.2; Numbers within strings are compared using numeric value, that is, Foo2.txt < Foo7.txt < Foo25.txt; only applies to compare methods, not find
NSDiacriticInsensitiveSearch128If specified, ignores diacritics (o-umlaut = o)
NSWidthInsensitiveSearch256If specified, ignores width differences ('a' = UFF41)
NSForcedOrderingSearch512If specified, comparisons are forced to return either NSOrderedAscending or NSOrderedDescending if the strings are equivalent but not strictly equal, for stability when sorting (e.g. "aaa" > "AAA" with NSCaseInsensitiveSearch specified)

The constants NSDiacriticInsensitiveSearch, NSWidthInsensitiveSearch and NSForcedOrderingSearch are only for Mac OS X 10.5 and newer versions.

Returns value constants:

Some examples using this method:

Feedback, Comments & Corrections

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

MBS Xojo Chart Plugins