StringParse(string, string, int)
Given a source string and a delimiter string, this function searches the source string for the delimiter string and returns the portion of the source string that appears either left of the first occurrence of the delimiter, or right of the last occurrence of the delimiter.
string StringParse( string sSource, string sDelimiter = " ", int bRightToLeft = FALSE );
Parameters
sSource
The source string to be scanned.
sDelimiter
The delimiter string searched for inside the source string. (Default: a space " ")
bRightToLeft
A boolean parameter specifying the search direction. (Default: FALSE (left to right))
Description
Given a source string and a delimiter string, this function searches the source string for the delimiter string and returns the portion of the source string that appears either left of the first occurrence of the delimiter, or right of the last occurrence of the delimiter.
Remarks
If the delimiter string is either empty ("") or not found in the source string, the entire source string is returned.
If the boolean parameter bRightToLeft is TRUE, the source string is scanned from right to left for the delimiter and returns the portion of the source string to the right of the first occurrence of the delimiter found.
If the boolean parameter bRightToLeft is FALSE (the default), the source string is scanned from left to right for the delimiter and returns the portion of the source string to the left of the first occurrence of the delimiter found.
Requirements
#include "x3_inc_string"
Version
1.69
Example
// In this example the OnPlayerChat event is hooked to allow players to enter emote // commands in the chat window to have their avatar carry them out. They type in // the keyword "*emote " followed by one of several supported emote commands // (e.g. *emote worship). // OnPlayerChat script to support chat-based emote commands. #include "x3_inc_string" void main() { // Find the chatting player. Do nothing if a valid PC could not be found. object oPC = GetPCChatSpeaker(); if(!GetIsPC(oPC)) { return; } // Get the text the player typed into the chat window. string sChatText = GetPCChatMessage(); // Strip off all leading and trailing spaces. StringRemoveParsed(sChatText, ""); StringRemoveParsed(sChatText, "", " ", TRUE); // Convert the string to all lower case letters. sChatText = GetStringLowerCase(sChatText); // If the first word is not the keyword "*emote" then do nothing further. if(StringParse(sChatText) != "*emote") { return; } // Extract the emote command from the chat text. string sEmoteCommand = StringRemoveParsed(sChatText, "*emote"); // Determine the emote animation number and duration. Looping animations are // executed for 1 game day which the player can abort by clicking the mouse. int iEmoteNumber = 0; float fEmoteDuration = 0.0; if(sEmoteCommand == "worship") { iEmoteNumber = ANIMATION_LOOPING_WORSHIP; fEmoteDuration = HoursToSeconds(24); } else if(sEmoteCommand == "sit") { iEmoteNumber = ANIMATION_LOOPING_SIT_CROSS; fEmoteDuration = HoursToSeconds(24); } else if(sEmoteCommand == "beg") { iEmoteNumber = ANIMATION_LOOPING_TALK_PLEADING; fEmoteDuration = HoursToSeconds(24); } else if(sEmoteCommand == "laugh") { iEmoteNumber = ANIMATION_LOOPING_TALK_LAUGHING; fEmoteDuration = HoursToSeconds(24); } else if(sEmoteCommand == "scold") { iEmoteNumber = ANIMATION_LOOPING_TALK_FORCEFUL; fEmoteDuration = HoursToSeconds(24); } else if(sEmoteCommand == "fall forward") { iEmoteNumber = ANIMATION_LOOPING_DEAD_FRONT; fEmoteDuration = HoursToSeconds(24); } else if( sEmoteCommand == "fall backward" ) { iEmoteNumber = ANIMATION_LOOPING_DEAD_BACK; fEmoteDuration = HoursToSeconds(24); } else if(sEmoteCommand == "salute") { iEmoteNumber = ANIMATION_FIREFORGET_SALUTE; } else if(sEmoteCommand == "read") { iEmoteNumber = ANIMATION_FIREFORGET_READ; } else if(sEmoteCommand == "greet") { iEmoteNumber = ANIMATION_FIREFORGET_GREETING; } else if(sEmoteCommand == "drink") { iEmoteNumber = ANIMATION_FIREFORGET_DRINK; } else if(sEmoteCommand == "bow") { iEmoteNumber = ANIMATION_FIREFORGET_BOW; } // If the emote command was recognized, make the player perform the appropriate // emote animation and cancel the chat so that other players won't see the // emote command typed in by the player. Otherwise do nothing more. if(iEmoteNumber > 0) { AssignCommand(oPC, ClearAllActions()); AssignCommand(oPC, ActionPlayAnimation(iEmoteNumber, 1.0, fEmoteDuration)); SetPCChatVolume(TALKVOLUME_SILENT_TALK); SetPCChatMessage(); } }
See Also
functions: | StringRemoveParsed | StringReplace | FindSubString | GetSubString |
categories: | String Functions |
author: Axe Murderer, editors: Mistress, Kolyana, contributor: Kookoo