RobotStudio event

Character comparison

Hello,
will I be able make similiar program like I done in C++ ?  

int main(){
    string word = "car";
    
    for(int i = 0; i < word.length(); i++) {
    char x = word[i];
    
    switch(x){
    case 'c':
          GOTO Path_10
          break;
    case 'a':
          GOTO Path_20
          break;
    case 'r':
          GOTO Path_30
          break;
        }
    } 
}

Problem is that I don't know how should I comparison character in string in robotstudio. I try command TEST but there I can only comparison number. 

Thanks for help.

Comments

  • graemepaulin
    edited January 2017

    PERS string test_txt:="up";

    PROC main()

        TEST test_txt

                 CASE "up":

                       TPWrite "up";

                CASE "down":

                       TPWrite "down";

                DEFAULT:

                     TPWrite "other";

        ENDTEST

    ENDPROC


    Use the string functions to manipulate your text and extract individual letters (see attached).

  • Thank you
  • <div>&nbsp; PROC main()<br></div><div>&nbsp; &nbsp; VAR string x;<br></div><div>&nbsp; &nbsp; VAR string word := "car";<br></div><div>&nbsp; &nbsp; VAR num counter := 1;<br></div><div>&nbsp; &nbsp;&nbsp;<br></div><div>&nbsp; &nbsp; ! loop all chars<br></div><div>&nbsp; &nbsp; WHILE counter <= StrLen(word) DO<br></div><div>&nbsp; &nbsp; &nbsp;&nbsp;<br></div><div>&nbsp; &nbsp; &nbsp; ! get char<br></div><div>&nbsp; &nbsp; &nbsp; x := StrPart(word, counter, 1);<br></div><div>&nbsp; &nbsp; &nbsp;&nbsp;<br></div><div>&nbsp; &nbsp; &nbsp; ! switch based on char<br></div><div>&nbsp; &nbsp; &nbsp; TEST x<br></div><div>&nbsp; &nbsp; &nbsp; CASE "c": GOTO Path_10;<br></div><div>&nbsp; &nbsp; &nbsp; CASE "a": GOTO Path_20;<br></div><div>&nbsp; &nbsp; &nbsp; CASE "r": GOTO Path_30;<br></div><div>&nbsp; &nbsp; &nbsp; ENDTEST<br></div><div>&nbsp; &nbsp; &nbsp;&nbsp;<br></div><div>&nbsp; &nbsp; ENDWHILE<br></div><div>&nbsp; &nbsp;&nbsp;<br></div><div>&nbsp; &nbsp; ! dummy labels<br></div><div>&nbsp; &nbsp; Path_10:<br></div><div>&nbsp; &nbsp; Path_20:<br></div><div>&nbsp; &nbsp; Path_30:<br></div><div><br></div><div>&nbsp; ENDPROC</div>

  • I already solve my problem but thank you !