string source = "/once/upon/a/time/"; int count = 0; foreach (char c in source) if (c == '/') count++;