<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-CN">
	<id>http://i.bnu.edu.cn/wiki/index.php?action=history&amp;feed=atom&amp;title=LlSubStringIndex</id>
	<title>LlSubStringIndex - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="http://i.bnu.edu.cn/wiki/index.php?action=history&amp;feed=atom&amp;title=LlSubStringIndex"/>
	<link rel="alternate" type="text/html" href="http://i.bnu.edu.cn/wiki/index.php?title=LlSubStringIndex&amp;action=history"/>
	<updated>2026-06-01T02:50:14Z</updated>
	<subtitle>本wiki的该页面的版本历史</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>http://i.bnu.edu.cn/wiki/index.php?title=LlSubStringIndex&amp;diff=519&amp;oldid=prev</id>
		<title>Wzc：创建页面，内容为“{{LSL Header|ml=*}}{{LSLC|Keywords}}{{LSLC|Flow Control}}{{LSLC|}}   {{函数详情 |函数名 = Function: integer llSubStringIndex( string source, string pattern );…”</title>
		<link rel="alternate" type="text/html" href="http://i.bnu.edu.cn/wiki/index.php?title=LlSubStringIndex&amp;diff=519&amp;oldid=prev"/>
		<updated>2020-07-27T07:43:59Z</updated>

		<summary type="html">&lt;p&gt;创建页面，内容为“{{LSL Header|ml=*}}{{LSLC|Keywords}}{{LSLC|Flow Control}}{{LSLC|}}   {{函数详情 |函数名 = Function: integer llSubStringIndex( string source, string pattern );…”&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{LSL Header|ml=*}}{{LSLC|Keywords}}{{LSLC|Flow Control}}{{LSLC|}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{函数详情&lt;br /&gt;
|函数名 = Function: integer llSubStringIndex( string source, string pattern );&lt;br /&gt;
|参数= 参数：•字符串源-要搜索的内容（haystack）&lt;br /&gt;
&lt;br /&gt;
•字符串源（string source）-要搜索的内容（haystack）&lt;br /&gt;
&lt;br /&gt;
•字符串模式（string pattern）-要搜索的内容（针）&lt;br /&gt;
&lt;br /&gt;
如果在源代码中找不到模式，则返回-1。&lt;br /&gt;
&lt;br /&gt;
字符串中第一个字符的索引为0&lt;br /&gt;
|返回值= 返回值：返回一个整数，该整数是源中模式的第一个实例的索引。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|注意事项=执行文字匹配（区分大小写）。&lt;br /&gt;
不支持通配符和正则表达式。&lt;br /&gt;
如果pattern是空字符串，则返回的值是0而不是-1。&lt;br /&gt;
没有从特定偏移量开始搜索字符串的函数。另请参阅，以获取从末尾搜索的函数。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|示例=&lt;br /&gt;
示例1&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
default&lt;br /&gt;
{&lt;br /&gt;
    touch_start(integer num_detected)&lt;br /&gt;
    {&lt;br /&gt;
        string  name       = llDetectedName(0);&lt;br /&gt;
        integer spaceIndex = llSubStringIndex(name, &amp;quot; &amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
//      no conditional check is needed for (spaceIndex == -1)&lt;br /&gt;
//      because we KNOW the legacy name must have a space&lt;br /&gt;
 &lt;br /&gt;
//      extract the substring from the first character to the one before the space&lt;br /&gt;
        string  firstName  = llGetSubString(name, 0, spaceIndex - 1);&lt;br /&gt;
 &lt;br /&gt;
        llSay(PUBLIC_CHANNEL, firstName + &amp;quot; touched me.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
示例2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
default&lt;br /&gt;
{&lt;br /&gt;
    state_entry()&lt;br /&gt;
    {&lt;br /&gt;
        llSensorRepeat(&amp;quot;&amp;quot;, NULL_KEY, AGENT_BY_LEGACY_NAME, PI, 96.0, 20);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    sensor(integer num_detected)&lt;br /&gt;
    {&lt;br /&gt;
    //  Loop through all the sensor data and match against &amp;quot; Linden&amp;quot;, &lt;br /&gt;
    //  this causes it to match with any last name of Linden (since there can't be spaces before the firstname)&lt;br /&gt;
    //  Alternatively you could match a firstname with &amp;quot;FirstName &amp;quot; or anything else&lt;br /&gt;
 &lt;br /&gt;
        integer index;&lt;br /&gt;
        do&lt;br /&gt;
        {&lt;br /&gt;
            key avatarKey = llDetectedKey(index);&lt;br /&gt;
            string avatarLegacyName = llDetectedName(index);&lt;br /&gt;
 &lt;br /&gt;
        //  watch out for the bitwise-NOT (~)&lt;br /&gt;
        //  the next line translates to if (indexOfSearchedStringInOtherString != -1)&lt;br /&gt;
            integer isReallyALinden = ~llSubStringIndex(avatarLegacyName, &amp;quot; Linden&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
            if (isReallyALinden)&lt;br /&gt;
                llInstantMessage(avatarKey, &amp;quot;Hello, I see you!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        while (++index &amp;lt; num_detected);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
基本示例：&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
integer index = llSubStringIndex(&amp;quot;string data&amp;quot;,&amp;quot;TEST&amp;quot;);&lt;br /&gt;
if(index == -1) {&lt;br /&gt;
    llSay(PUBLIC_CHANNEL,&amp;quot;TEST was not found in the string&amp;quot;);&lt;br /&gt;
} else {&lt;br /&gt;
    llSay(PUBLIC_CHANNEL,&amp;quot;TEST was found in the string.&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
奶酪串（String Cheese）&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//This example shows how you can ask if a word or group of words is in a given string.&lt;br /&gt;
//There is a limitation with this function. Your search of the string is for an exact match (case sensitive)&lt;br /&gt;
//so the string_example below would be hard to match.&lt;br /&gt;
 &lt;br /&gt;
string string_example = &amp;quot;ThIs serVes As aN exaMplE sTrinG. It ISn't toO coMPleX bUt HaS sOme mIlD vARietY&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
//If you chat a question &amp;quot;Search for search_word&amp;quot; within range of the object this script is in&lt;br /&gt;
//it will recognize (by searching the chat msg) the &amp;quot;search for&amp;quot; part and take the word or words following it&lt;br /&gt;
//and check the string_example for those words.&lt;br /&gt;
 &lt;br /&gt;
string search_test_a = &amp;quot;seArCh foR&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
//The example below works the same way but searches for the word in front of the recognized trigger question.&lt;br /&gt;
 &lt;br /&gt;
string search_test_b = &amp;quot;is the word I seek&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
//Using this variable provides a way to manipulate the word(s) during the script without damaging the msg.&lt;br /&gt;
 &lt;br /&gt;
string search_word;&lt;br /&gt;
 &lt;br /&gt;
// Provide a mnemonic for the -1 return code that means NOT FOUND&lt;br /&gt;
integer NOT_FOUND = -1;&lt;br /&gt;
 &lt;br /&gt;
default&lt;br /&gt;
{&lt;br /&gt;
    on_rez(integer param)//Although reseting the script on_rez provides many benefits&lt;br /&gt;
    { //in some cases it would be a bad idea because stored variables, lists and queued events would be trashed.&lt;br /&gt;
        llResetScript();&lt;br /&gt;
    }&lt;br /&gt;
    state_entry()&lt;br /&gt;
    {   //This is just for fun (but better to know what object is talking to you).&lt;br /&gt;
        llSetObjectName(&amp;quot;String Cheese&amp;quot;);&lt;br /&gt;
        llListen(PUBLIC_CHANNEL, &amp;quot;&amp;quot;, llGetOwner(), &amp;quot;&amp;quot;);//Listen to you on the public chat channel for everything you say.&lt;br /&gt;
    }&lt;br /&gt;
    listen(integer chan, string name, key id, string msg)&lt;br /&gt;
    {&lt;br /&gt;
        if(llSubStringIndex(llToUpper(msg), llToUpper(search_test_a)) != NOT_FOUND)&lt;br /&gt;
        {&lt;br /&gt;
            search_word = llStringTrim(llGetSubString(msg, llStringLength(search_test_a), -1), STRING_TRIM);&lt;br /&gt;
            if(llSubStringIndex(llToUpper(string_example), llToUpper(search_word)) != NOT_FOUND)&lt;br /&gt;
            {&lt;br /&gt;
                llSay(PUBLIC_CHANNEL, &amp;quot;I have found the word &amp;quot; + &amp;quot;''&amp;quot; + search_word + &amp;quot;''&amp;quot; + &amp;quot; in the example string&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else                         &lt;br /&gt;
            {&lt;br /&gt;
                llSay(PUBLIC_CHANNEL, &amp;quot;I cannot find the word &amp;quot; + &amp;quot;''&amp;quot; + search_word + &amp;quot;''&amp;quot; + &amp;quot; in the example string.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        if(llSubStringIndex(msg, search_test_b) != NOT_FOUND)&lt;br /&gt;
        {&lt;br /&gt;
            search_word = llStringTrim(llGetSubString(msg, 0, (llSubStringIndex(msg, search_test_b)-1)), STRING_TRIM);&lt;br /&gt;
            if(llSubStringIndex(string_example, search_word) != NOT_FOUND)&lt;br /&gt;
            {&lt;br /&gt;
                llSay(PUBLIC_CHANNEL, &amp;quot;I have found the word &amp;quot; + &amp;quot;''&amp;quot; + search_word + &amp;quot;''&amp;quot; + &amp;quot; in the example string&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                llSay(PUBLIC_CHANNEL, &amp;quot;I cannot find the word &amp;quot; + &amp;quot;''&amp;quot; + search_word + &amp;quot;''&amp;quot; + &amp;quot; in the example string.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
有用的片段：&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
测试一个字符串是否包含另一个字符串的副本：&lt;br /&gt;
1简洁与传统：&lt;br /&gt;
nteger contains(string haystack, string needle) // http://wiki.secondlife.com/wiki/llSubStringIndex&lt;br /&gt;
{&lt;br /&gt;
    return 0 &amp;lt;= llSubStringIndex(haystack, needle);&lt;br /&gt;
}&lt;br /&gt;
integer startswith(string haystack, string needle) // http://wiki.secondlife.com/wiki/llSubStringIndex&lt;br /&gt;
{&lt;br /&gt;
    return llDeleteSubString(haystack, llStringLength(needle), 0x7FFFFFF0) == needle;&lt;br /&gt;
}&lt;br /&gt;
integer endswith(string haystack, string needle) // http://wiki.secondlife.com/wiki/llSubStringIndex&lt;br /&gt;
{&lt;br /&gt;
    return llDeleteSubString(haystack, 0x8000000F, ~llStringLength(needle)) == needle;&lt;br /&gt;
}&lt;br /&gt;
注意：上面的一些片段返回结果时从未调用llSubStringIndex。&lt;br /&gt;
2聪明更小（计算包含在~54字节而不是~60字节）：&lt;br /&gt;
注意：上面的一些片段返回结果时从未调用llSubStringIndex。&lt;br /&gt;
2聪明更小（计算包含在~54字节而不是~60字节）：&lt;br /&gt;
integer contains(string haystack, string needle) // http://wiki.secondlife.com/wiki/llSubStringIndex&lt;br /&gt;
{&lt;br /&gt;
    return ~llSubStringIndex(haystack, needle);&lt;br /&gt;
}&lt;br /&gt;
注意：llSubStringIndex函数只在找不到时返回-1，~运算符只为-1返回零，因此巧妙的组合~llSubStringIndex只为未找到返回零，否则为已找到返回非零。&lt;br /&gt;
注意：当我们的代码竞赛者和效率测试人员工具测量表达式{contains（“wiki.secondlife.com网站“，”wiki“）；}。&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|相关函数=&lt;br /&gt;
[[llListFindList]] –在另一个列表中查找列表&lt;br /&gt;
&lt;br /&gt;
[[llGetSubString]]–复制字符串的一部分	&lt;br /&gt;
&lt;br /&gt;
[[uSubStringLastIndex]]	–返回一个整数，它是源中最后一个模式的索引。&lt;br /&gt;
&lt;br /&gt;
|相关事件=无&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Wzc</name></author>
		
	</entry>
</feed>