Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string rawNames = "Hasan@David@Siti@Malvin@Iven"
- string[] splittedNames;
- // Count the number of '@'s in string rawNames to determine the size of splittedNames array.
- int atCounter = 0;
- for(int i = 0 ; i < rawNames.length ; i++)
- {
- if(rawNames[i] == '@')
- {
- atCounter++;
- }
- }
- // Create new splittedNames based on counted '@'s + 1 (words are +1 of '@'s count)
- splittedNames = new string[atCounter + 1];
- // Split names based on '@'s
- int currentIndex = 0; // Buat nentuin index ke berapa yang di-assign.
- for(int i = 0 ; i < rawNames.length ; i++)
- {
- if(rawNames[i] != '@')
- {
- splittedNames[currentIndex] += rawNames[i];
- }
- else
- {
- currentIndex++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement