Advertisement
mtrower

splitstring.nss

Jan 15th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. struct Nums {
  2.     int num1;
  3.     int num2;
  4.     int num3;
  5. };
  6.  
  7. struct SearchResult {
  8.     string result;
  9.     string remainder;
  10. };
  11.  
  12. struct SearchResult getNextNum(string encoded) {
  13.     struct SearchResult result;
  14.     int idx = 0;
  15.  
  16.     idx = FindSubString(encoded, " ");
  17.     if (idx == -1) {
  18.         result.result = encoded;
  19.         result.remainder = "";
  20.     } else {
  21.         result.result = GetSubString(encoded, 0, idx);
  22.         result.remainder = GetSubString(encoded, idx + 1,
  23.                                         GetStringLength(encoded) - idx - 1);
  24.     }
  25.  
  26.     return result;
  27. }
  28.  
  29. struct Nums decode(string encoded) {
  30.     struct Nums nums;
  31.     struct SearchResult result;
  32.  
  33.     result = getNextNum(encoded);
  34.     nums.num1 = StringToInt(result.result);
  35.  
  36.     result = getNextNum(result.remainder);
  37.     nums.num2 = StringToInt(result.result);
  38.  
  39.     result = getNextNum(result.remainder);
  40.     nums.num3 = StringToInt(result.result);
  41.  
  42.     return nums;
  43. }
  44.  
  45. void main() {
  46.     string myString = "1 123 32";
  47.     struct Nums nums = decode(myString);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement