• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] String inside a string

Status
Not open for further replies.
Level 4
Joined
Mar 26, 2008
Messages
100
Is there a way to detect if a string has a certain word\letter\whatever in it ?

I know the name of a unit and I wish to know if it contains "Ork".
 
Level 16
Joined
Feb 22, 2006
Messages
960
here a simple function for you... how to use

copy this into your mapheader:
JASS:
function wordloop takes string s, string search returns boolean
    local integer i = 0
    local integer k = 0
    local string tmpS
    local boolean b = false
    loop
        exitwhen i >= StringLength(s) or b == true
        loop
            exitwhen k >= StringLength(s) or b == true
            set tmpS = SubString(s,i,k) 
            if tmpS == search then
                set b = true
            endif
            set k = k + 1                  
        endloop
        set k = 0
        set i = i + 1
    endloop
    return b
endfunction

or here a GUI version.. but I prefere the Jass Version

  • WordSearchGUI
    • Ereignisse
      • Spieler - Spieler 1 (Rot) types a chat message containing -test as Exakte Ãœbereinstimmung
    • Bedingungen
    • Aktionen
      • Set gg = Hi my name is god!
      • Set searchWord = name
      • For each (Integer A) from 0 to (Length of gg), do (Actions)
        • Schleifen - Aktionen
          • For each (Integer B) from 0 to (Length of gg), do (Actions)
            • Schleifen - Aktionen
              • Custom script: set udg_tmpString = SubString(udg_gg,bj_forLoopAIndex,bj_forLoopBIndex)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • 'IF'-Bedingungen
                  • tmpString Gleich searchWord
                • 'THEN'-Aktionen
                  • Set bol = True
                • 'ELSE'-Aktionen
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • 'IF'-Bedingungen
          • bol Gleich True
        • 'THEN'-Aktionen
          • Spiel - Display to (All players) for 30.00 seconds the text: True
        • 'ELSE'-Aktionen
          • Spiel - Display to (All players) for 30.00 seconds the text: False
for gui you need 3 strings (gg,searchWord and tmpString and also a boolean bol)
 
Status
Not open for further replies.
Top