playMaker

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

stoffl

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
StringContainsCaseInsensitive[SOLVED]
« on: November 06, 2017, 04: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, 08:44:48 AM by stoffl »

stoffl

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
Re: StringContainsCaseInsensitive
« Reply #1 on: November 06, 2017, 08: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: 12351
  • Official Playmaker Support
    • View Profile
Re: StringContainsCaseInsensitive[SOLVED]
« Reply #2 on: November 08, 2017, 01:19:44 AM »
Hi,

 Cool!

 Bye,

 Jean