Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: stoffl on November 06, 2017, 06:53:51 AM
-
Hi,
I tried to implement:
if (myString.IndexOf(itemToLook, System.StringComparison.CurrentCultureIgnoreCase) > 0) {
Debug.Log("String found");
} else {
Debug.Log("String not found");
}
With no luck. Is there an easy way to achieve this?
For my propose i need to check all lower upper case possibilities
- for example: JEAN, JEAn, JEaN, JEan,... is contained in a string.
I achieved this only by bruteforcing all possible variations of a string to an array in order to loop through and check all seperate with string contains.(which causes memory to jump up)
Thank's for your help
-
Sorry it already worked, i just placed a variable wrong. Heres the code if somebody needs it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("String")]
public class StringContainsCaseInsensitive : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The String variable to test.")]
public FsmString stringVariable;
[RequiredField]
[Tooltip("Test if the String variable contains this string.")]
public FsmString containsString;
[Tooltip("Event to send if true.")]
public FsmEvent trueEvent;
[Tooltip("Event to send if false.")]
public FsmEvent falseEvent;
[UIHint(UIHint.Variable)]
[Tooltip("Store the true/false result in a bool variable.")]
public FsmBool storeResult;
[Tooltip("Repeat every frame. Useful if any of the strings are changing over time.")]
public bool everyFrame;
public override void Reset()
{
stringVariable = null;
containsString = null;
trueEvent = null;
falseEvent = null;
storeResult = null;
everyFrame = false;
}
public override void OnEnter()
{
DoStringContains();
if (!everyFrame)
{
Finish();
}
}
public override void OnUpdate()
{
DoStringContains();
}
void DoStringContains()
{
if (stringVariable.IsNone || containsString.IsNone) return;
var contains = stringVariable.Value.IndexOf (containsString.Value, System.StringComparison.CurrentCultureIgnoreCase) > 0;
if (storeResult != null)
{
storeResult.Value = contains;
}
if (contains && trueEvent != null)
{
Fsm.Event(trueEvent);
return;
}
if (!contains && falseEvent != null)
{
Fsm.Event(falseEvent);
}
}
}
}
-
Hi,
Cool!
Bye,
Jean