Last post Jul 16, 2014 10:51 AM by TmoodASP
Jul 16, 2014 08:47 AM|TmoodASP|LINK
I have a string that goes something like this: 1,3,4,5
I'd like to explode/split them and identify each. Is there such option within Razor? I am unable to find it..
To further advance what I'm doing -- I have a checklist, and each checklist is correspond with #. The first check item is 1, second check item is 2, etc.
Then after pulling from database, I want to be able to know which checklist is checked, but need to take apart 1,3,4,5. Thus, ensure check item 1 is checked, check item 3 is checked, and so on.
Any assistance would be greatly appreciated! Many thanks in advance!!
Jul 16, 2014 08:52 AM|emu42|LINK
string lString = "1,2,3,4,5";
List<string> lExploded = lString.Split(',');
Jul 16, 2014 09:37 AM|Rion Williams|LINK
If you have a string in this format, generally the
String.Split() method is the easiest way to handle this as seen below :
// Your string
string s = "1,3,4,5";
// Split it into an array
string sa = s.Split(','); // yields ["1","3","4","5"]
string.split() function which functions identically to the C# version seen above.
Do you have any examples of the markup or code that you are using? It may make it a bit easier to provide you with a more detailed response.
Jul 16, 2014 10:51 AM|TmoodASP|LINK
Great! That helps!
My next challenge is, trying to list all the checklist item #1-5, but noticed that #2 is not part of the string. Meaning it was not checked.
So I want to create a markup of checklist item showing #1, #3, #4, #5 checked but not #2.
Each time I try using loop, I ends up repeating the checklist item. Does that make sense??