0

I have one string, that is = s = "Pedro Martinez, Defense"

I want to split the string before the comma and after the comma, store those cuts on 2 variables, for example:

I think that I need to use the string.gmatch function or string.sub

How can I do that?

greatwolf
  • 20,287
  • 13
  • 71
  • 105
Wayra
  • 63
  • 7

1 Answers1

2

The accepted answer at How to convert GPS coordinates to decimal in Lua? shows how to use string.match and patterns. Applying the same techniques as mentioned there, you could use

local name, expertise = string.match(s, "(.*),%s*(%a*)")

which would lead to name being "Pedro Martinez" and expertise being "Defense".

Community
  • 1
  • 1
Oliver
  • 27,510
  • 9
  • 72
  • 103