playMaker

Author Topic: StringContainsCaseInsensitive[SOLVED]  (Read 1565 times)

stoffl

  • Playmaker Newbie
  • *
  • Posts: 19
StringContainsCaseInsensitive[SOLVED]
« on: November 06, 2017, 06:53:51 AM »
Hi,
I tried to implement:
Code: [Select]
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
« Last Edit: November 06, 2017, 10:44:48 AM by stoffl »

stoffl

  • Playmaker Newbie
  • *
  • Posts: 19
Re: StringContainsCaseInsensitive
« Reply #1 on: November 06, 2017, 10:41:34 AM »
Sorry it already worked, i just placed a variable wrong. Heres the code if somebody needs it:

Code: [Select]
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);
}
}


}

}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: StringContainsCaseInsensitive[SOLVED]
« Reply #2 on: November 08, 2017, 03:19:44 AM »
Hi,

 Cool!

 Bye,

 Jean