Advertisement
moseskarunia

Untitled

Mar 30th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. string rawNames = "Hasan@David@Siti@Malvin@Iven"
  2. string[] splittedNames;
  3.  
  4. // Count the number of '@'s in string rawNames to determine the size of splittedNames array.
  5. int atCounter = 0;
  6. for(int i = 0 ; i < rawNames.length ; i++)
  7. {
  8. if(rawNames[i] == '@')
  9. {
  10. atCounter++;
  11. }
  12. }
  13.  
  14. // Create new splittedNames based on counted '@'s + 1 (words are +1 of '@'s count)
  15. splittedNames = new string[atCounter + 1];
  16.  
  17. // Split names based on '@'s
  18. int currentIndex = 0; // Buat nentuin index ke berapa yang di-assign.
  19. for(int i = 0 ; i < rawNames.length ; i++)
  20. {
  21. if(rawNames[i] != '@')
  22. {
  23. splittedNames[currentIndex] += rawNames[i];
  24. }
  25. else
  26. {
  27. currentIndex++;
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement