0

This question is similar to this one, however, I would like to do this without having to create any extra separated function, is it possible?

What do I have:

  • Load_XXXX.5gpl_TempCycle
  • RO_Mass_Load_XXXX.AAAA-31974-B
  • RO_Mass_Load_XXXX.AAAA-31980
  • RO_Mass_Load_Test_4a-B_TempCycle_20170427-41309
  • Load_Test_4a_TempCycle

I wanna take out:

  • only the ones that start with "Load_".
  • or finishes with "-B"

Problem: If I use Contains(string), it will take out all of them.

What do I need: A Contain (or something else?) that takes out strings that start with "Load_" or finishes with "-B".

Result expect:

  • RO_Mass_Load_XXXX.AAAA-31980
  • RO_Mass_Load_Test_4a-B_UUU_20170427-41309

Code not working(it gets everything out):

if (item.Full_File_Name.Contains("-B") || item.Full_File_Name.Contains("Load"))

Any ideas or help?

Fabio Soares
  • 101
  • 2
  • 12

1 Answers1

4

You have prepared functions for that: StartsWith and EndsWith

if (item.Full_File_Name.EndsWith("-B") || item.Full_File_Name.StartsWith("Load"))

If we want one or the other, we should use:

if (!item.Full_File_Name.EndsWith("-B") && !item.Full_File_Name.StartsWith("Load_"))
zx485
  • 28,498
  • 28
  • 50
  • 59
Ofir Winegarten
  • 9,215
  • 2
  • 21
  • 27
  • 1
    Wow, that was juvenile from my part. Thank you! – Fabio Soares Jul 14 '17 at 18:33
  • @Fabio Soares will it serve your purpose? I think it will also return those ones who starts with Load as well which is different from your Expected Result. – Ramankingdom Jul 14 '17 at 18:54
  • @Ramankingdom, for my case it will work... I was trying to eliminate Load_... or ...-B; If B or Load are in the middle, I don't care. During my tests, it works. – Fabio Soares Jul 14 '17 at 19:15
  • @Ramankingdom, you are right! The correct should be: if (!item.Full_File_Name.EndsWith("-B") && !item.Full_File_Name.StartsWith("Load_")) – Fabio Soares Jul 14 '17 at 19:16