N
N
NONAME82017-09-23 13:29:11
Objective-C
NONAME8, 2017-09-23 13:29:11

How to count a string in objective-c?

Hello!
Here in C++, using cin.getline() you can read lines with a space.
But as I understand it, in the objective-c language there is only scanf () , which can only count 1 word.
What object then to read out lines?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Globak, 2017-09-25
@NONAME8

It became interesting and decided to google "Objective-C console readline" and somewhere in the 6th place I found what I was looking for =) I tested it and everything works. Hold =)

NSLog(@"type a text:\n");
NSFileHandle *input = [NSFileHandle fileHandleWithStandardInput];
NSData *inputData = [input availableData];
        
NSString *str = [[NSString alloc] initWithData:inputData encoding:NSUTF8StringEncoding];
NSLog(@"Text: %@", str);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question