Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用字符串'/ObjC/GNUstep/mingw/bin';_Objective C_Nsstring - Fatal编程技术网

Objective c 使用字符串'/ObjC/GNUstep/mingw/bin';

Objective c 使用字符串'/ObjC/GNUstep/mingw/bin';,objective-c,nsstring,Objective C,Nsstring,使用字符串“/ObjC/GNUstep/mingw/bin”创建字符串对象 打印路径中的每个组件: ObjC GNUstep mingw bin 如何做到这一点,我不能排除“/”而打印,plz帮助我假设这是家庭作业,在这种情况下,重点是学习算法。这意味着没有花哨的类库函数(否定算法学习)和伪代码(这样你就不会被发现剽窃): 你应该看看课程参考,特别是“使用路径”部分。Mate,你甚至没有试图掩盖这是家庭作业的事实:-) string s = "/ObjC/GNUstep/mingw/bin"

使用字符串“/ObjC/GNUstep/mingw/bin”创建字符串对象

打印路径中的每个组件:

ObjC
GNUstep
mingw
bin

如何做到这一点,我不能排除“/”而打印,plz帮助

我假设这是家庭作业,在这种情况下,重点是学习算法。这意味着没有花哨的类库函数(否定算法学习)和伪代码(这样你就不会被发现剽窃):

你应该看看课程参考,特别是“使用路径”部分。

Mate,你甚至没有试图掩盖这是家庭作业的事实:-)
string s = "/ObjC/GNUstep/mingw/bin"

# Output the first character if it's not '/'
#   ('if' to prevent mishandling empty strings).

if s.len() > 0:
    if s[0] != "/":
        output s[0]

# Output all other character except last, translating '/' into newline
#   ('if' prevents mishandling strings two chars or less).

if s.len() > 2:
    for i goes from 1 to s.len()-2:
        if s[i] == "/":
            output newline
        else:
            output s[i]

# Output last character if not '/' 
#   ('if' is to prevent mishandling one-char strings)

if s.len() > 1:
    if s[s.len()-1] != "/":
        output s[s.len()-1]

output newline