playMaker

Author Topic: SOLVED! STRING.IndexOf() Action  (Read 833 times)

mrphilipjoel

  • Playmaker Newbie
  • *
  • Posts: 48
SOLVED! STRING.IndexOf() Action
« on: April 18, 2021, 09:46:15 PM »
Apparently there is no STRING.IndexOf() Action in the Ecosystem?

I tried writing one. I finally got all errors resolved, but its not returning the found index.

What I'm doing, is scraping the data from a webpage. I use wwwObject action to store it all as a string, but now I need to find specific data within that giant string. Once I located a word I know is in the data only once, I can start to trim the data. But, I need to know what index it is at first.

Code: [Select]
using UnityEngine;
using System;

namespace HutongGames.PlayMaker.Actions
{

[ActionCategory(ActionCategory.String)]
[Tooltip("Gets index of substring inside a string")]
public class StringGetIndexOf : FsmStateAction
{
[UIHint(UIHint.Variable)]
[Tooltip("String to search.")]
public FsmString stringToSearch;

[UIHint(UIHint.Variable)]
[Tooltip("String to find.")]
public FsmString stringToFind;

[UIHint(UIHint.Variable)]
[Tooltip("Index of found string.")]
public FsmInt stringIndex;


// Code that runs on entering the state.
public override void Reset()
{
stringToSearch = null;
stringToFind = null;
stringIndex = 0;
}

public override void OnEnter()
{

int stringIndex = (stringToSearch.Value).IndexOf(stringToFind.Value);
Finish();
}


}

}
« Last Edit: April 19, 2021, 01:19:09 PM by mrphilipjoel »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: STRING.IndexOf() Action
« Reply #1 on: April 19, 2021, 08:07:42 AM »
Hi.

Code: [Select]
int stringIndexShould be
Code: [Select]
stringIndex.Value

mrphilipjoel

  • Playmaker Newbie
  • *
  • Posts: 48
Re: STRING.IndexOf() Action
« Reply #2 on: April 19, 2021, 01:18:45 PM »
That was it! Thank you!