Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: mrphilipjoel on April 18, 2021, 09:46:15 PM

Title: SOLVED! STRING.IndexOf() Action
Post by: mrphilipjoel 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();
}


}

}
Title: Re: STRING.IndexOf() Action
Post by: djaydino on April 19, 2021, 08:07:42 AM
Hi.

Code: [Select]
int stringIndexShould be
Code: [Select]
stringIndex.Value
Title: Re: STRING.IndexOf() Action
Post by: mrphilipjoel on April 19, 2021, 01:18:45 PM
That was it! Thank you!