0

This is a java code for android. I'm trying to convert this to windows c#. I tried using split but I don't know how to go to the next element.

StringTokenizer st = new StringTokenizer(source, "><");
String marker = st.nextToken();

while(st.hasMoreTokens())
{   
nameLoop:
if(marker.equals("Name:"))
{
     while(st.hasMoreTokens())
     {  
          (marker.equals("strong"))
          {
               marker = st.nextToken();
               while(!(marker.equals("/strong")))
               {
                    Name = marker;
                    marker = st.nextToken();
               }
               break nameLoop;
           }

               marker = st.nextToken();
     }
 }
 else
     marker = st.nextToken();
 }
Patrick
  • 17,669
  • 6
  • 70
  • 85
pmark019
  • 1,199
  • 5
  • 15
  • 24

1 Answers1

2

You get an array from string.Split in C#, so you just loop through the elements using a foreach loop

string[] tokens = source.Split("><", StringSplitOptions.RemoveEmptyEntries);
foreach (string marker in tokens) {
    if (marker == "strong") {
    }
}

Or, if you want an index, you can use a for loop

string[] tokens = source.Split("><", StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < tokens.Length; ++i) {
    string marker = tokens[i];
    if (marker == "strong") {
    }
}
Patrick
  • 17,669
  • 6
  • 70
  • 85