Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Strings StringSetCompare  

StringSetCompare

StringSetCompare

Category: Strings
By : Encog Dod
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for StringSetCompare
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. StringSetCompare_1.lsl
1 // From the book:
2 //
3 // Scripting Recipes for Second Life
4 // by Jeff Heaton (Encog Dod in SL)
5 // ISBN: 160439000
6 X// Copyright 2007 by Heaton Research, Inc.
7 //
8 // This script may be freely copied and modified so long as this header
9 // remains unmodified.
10 //
11 // For more information about this book visit the following web site:
12 //
13 // http://www.heatonresearch.com/articles/series/22/
14
15 string CHARS = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
16
17
18 integer compareLen(string a, string b,integer len)
19 {
20 integer result = 0;
21 if(a != b)
22 {
23 integer index = 0;
24 do
25 {
26 string chara = llGetSubString(a,index,index);
27 string charb = llGetSubString(b,index,index);
28
29 integer posa = llSubStringIndex(CHARS ,chara);
30 integer posb = llSubStringIndex(CHARS ,charb);
31
32 if((posa >= 0) && (posb >= 0))
33 {
34 result = posa - posb;
35 }
36 else if(posa >= 0)
37 {
38 result = 1;
39 }
40 else if(posb >= 0)
41 {
42 result = -1;
43 }
44
45 if(result != 0) index = len;
46 ++index;
47
48 }
49 while(index < len);
50 }
51
52 return result;
53 }
54
55 integer compareNoCaseLen(string a, string b,integer len)
56 {
57 string stra = llToLower(a);
58 string strb = llToLower(b);
59 return compareLen(stra,strb,len);
60 }
61
62 integer compare(string a, string b)
63 {
64 integer lena = llStringLength(a);
65 integer lenb = llStringLength(b);
66 integer result;
67 if(lena < lenb)
68 result = compareLen(a,b,lena);
69 else
70 result = compareLen(a,b,lenb);
71
72 return result;
73 }
74
75
76 integer compareNoCase(string a, string b)
77 {
78 integer la = llStringLength(a);
79 integer lb = llStringLength(b);
80 string stra = llToLower(a);
81 string strb = llToLower(b);
82 integer result;
83 if(la < lb)
84 result = compareNoCaseLen(stra,strb,la);
85 else
86 result = compareNoCaseLen(stra,strb,lb);
87
88 return result;
89 }
90
91 // Some test uses
92 default
93 {
95 {
96 llSay(0, "compareNoCase(hello,HELLO): " + (string)compareNoCase("jeff","Jeff") );
97 llSay(0, "compare(hello,HELLO): " + (string)compare("jeff","Jeff") );
98 llSay(0, "compare(aaa,bbb): " + (string)compare("aaa","bbb") );
99 llSay(0, "compare(aaa,bbb): " + (string)compare("bbb","aaa") );
100 }
101 }

Back to the Best Free Tools in Second Life and OpenSim.