playMaker

Author Topic: Get string 'between two characters'  (Read 1106 times)

craigz

  • Beta Group
  • Full Member
  • *
  • Posts: 207
    • View Profile
    • Haven Made
Get string 'between two characters'
« on: June 08, 2019, 08:05:15 PM »
Hiya! :D

I went digging all over and can't seem to find this functionality  :) is there a way to get the string characters between two characters? Currently parsing a CSV and there's some nested data between a set of brackets.

Usecase: I'm splitting the string into substrings, but then need to get the data between the [ ]

"Brian,King,Longbeards[enemy],red"

Let me know if I'm missing something that may already exist, totally possible ;D

best,
craigz

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
    • View Profile
    • jinxtergames
Re: Get string 'between two characters'
« Reply #1 on: June 09, 2019, 02:32:52 AM »
Hi.

If your [ and ] are only once in the string , you could use 'String Get Index Of' (Ecosystem)
Get index of both [ and ]

Then use 'Get Substring'

You can use the [ index as start index (Possible index + 1)
Then from index ] deduct index [ to get the length (possible +1 or - 1)

I can't test at the moment if 1 needs to be added/subtracted from the indexes,
so you will have to try and find out.
Sorry for that.

craigz

  • Beta Group
  • Full Member
  • *
  • Posts: 207
    • View Profile
    • Haven Made
Re: Get string 'between two characters'
« Reply #2 on: June 17, 2019, 03:18:15 PM »
Hmm... that SOUNDS like it should work! :D

Yep the bookend characters are only once per string, though I know that's not always the case for most people :)

I will test this soon and report back, thank you for the insight! :D

cel

  • Full Member
  • ***
  • Posts: 109
    • View Profile
Re: Get string 'between two characters'
« Reply #3 on: November 27, 2019, 12:45:45 PM »
Hi, has this worked for you craigz?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15210
  • Official Playmaker Support
    • View Profile
Re: Get string 'between two characters'
« Reply #4 on: December 03, 2019, 11:07:22 PM »
Hi,

 regex must be a far more powerful way to get it done:

https://hutonggames.com/playmakerforum/index.php?topic=7005.0

Bye,

 Jean