Home > other >  Select dynamically a list of char in a string form a DLL
Select dynamically a list of char in a string form a DLL

Time:03-14

I'm new here and my English will not be the best you'll read today. I just imported from a DLL a list of "key"

(#8yg54w-#95jz#e-##9ixop-#7ps-#ny#9qv-# pzbk5-#bp669x-#bp6696-#bp6696-#bp6696-#bp6696-#bp6696-#fbhstu-#ehddtk-####9py),

we will name it this way it's a simple string. I need to select the "key" that compose this string after each # but it has to be done dynamically and not like you choose in an ArrayList [0,1,2 ...]. The end result should look like 8yg54w and after u got this one it's a loop and u get the next one, which means 95jz#e. The first "#" is a separator for each key. I wanna know how can I proceed to get each key after the first separator. I'll try to answer your questions because I think that there will be some, this is probably poorly explained, I apologize in advance! Thanks

CodePudding user response:

You can use Regex. But i am not sure whether you specification is complete, as it will also return e.g. "e" or "7ps".

string input = "(#8yg54w-#95jz#e-##9ixop-#7ps-#ny#9qv-# pzbk5-#bp669x-#bp6696-#bp6696-#bp6696-#bp6696-#bp6696-#fbhstu-#ehddtk-####9py)";
MatchCollection matches = Regex.Matches(input, @"(?<=\#)[A-Za-z1-9] ");
foreach (Match match in matches) {
    Console.WriteLine(match.Value);
}

Output:

8yg54w
95jz
e
9ixop
7ps
ny
9qv
bp669x
bp6696
bp6696
bp6696
bp6696
bp6696
fbhstu
ehddtk
9py

CodePudding user response:

This should return an array of keys.

string.Split("-#");

  • Related