lua split by backslash

  • Dear all, particularly Lua fans!


    I need to extract the A or B from

    Code
    0008,0008 Image Type: DERIVED\PRIMARY\SINGLE PLANE\SINGLE A
    or
    0008,0008 Image Type: DERIVED\PRIMARY\SINGLE PLANE\SINGLE B\STORE FLUORO


    I've been trying to work out how to do it with string.gmatch, some character escaping and regex, but both my Lua and my regex are too weak to get anything to work.


    Will anyone take pity on me?


    Your's hopefully...


    Ed


    P.S. if there is a function to call Data.ImageType[4] or equivalent that would be awesome too...

  • Hi,


    I typically use something like string.split:



    This would be used as follows:


    types = string.split(Data.ImageType, '\\')
    types[4] is what you want


    Marcel

  • That worked, and I'll keep it in reserve for the next time I need such a thing, but in the end I was over-complicating it!


    Code
    if string.find(Data.ImageType, 'SINGLE A') then


    was sufficient for this purpose.


    Thanks again.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!