Cannot get my paragraphs

Hello,

Given a textview “editionTextView” where some text has been pasted (various sources: Excel, Numbers, pdf) I try to get each line of the text like this:

    NSString *tempText = [self.editionTextView string];
    NSArray *linesArray =[NSArray arrayWithArray:[tempText componentsSeparatedByString:@"\n"]];

My array regularly returns empty. If the text is entered by keyboard, no problem. When the text is pasted, it’s wrong. However, the text appears normally paragraphed. I tried \r as separator without success.

To get rid of RTF and other surprises, I use a non-rich text for the text view. The problem is: what is the last character of the line? How could I “normalize” my text to get a correctly filled array?

Any ideas?

Try this instead:

Thank you Shane.

Dealing with users is just hell. Give me back the FORTRAN formatted entries.

The compiler complains that my newRecord variable is not used. And then in [aClass addObject:newRecord]; it tells me the same variable is not declared.

it must be a syntax error, or is it forbidden to create a variable into an IF test? Seems stupid.

You can’t create a variable inside an if unless you declare it before, like this:

NSArray *oneRecord = [NSArray arrayWithArray:[oneLine componentsSeparatedByString:@"\t"]];
    NSMutableDictionary *newRecord;
    if ( oneRecord.count == 1 ) {
        newRecord = [NSMutableDictionary dictionaryWithObjectsAndKeys:[oneRecord objectAtIndex:0], @"lastName", nil]; 
    } else {
        newRecord = [NSMutableDictionary dictionaryWithObjectsAndKeys:[oneRecord objectAtIndex:0], @"lastName",[oneRecord objectAtIndex:1], @"firstName", nil];
    }
    [aClass addObject:newRecord];

This will surely help :slight_smile:

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

Thank you leonsimard. Meanwhile, I’ve extracted not only the declaration of the IF test, but also the initialization of the dictionary. Then I add the keys/values into the test.

After thinking about it, I realized this is one drawback of C language. You can declare variables anywhere in code, but they have to stay in the scope. Inside an IF test, the compiler cannot decide if the variable has been declared or not. I thought: “You have to, moron, because this is an IF/ELSE statement! One of them is necessarily executed!” But. no.

Well, that’s one problem I have, accustomed to languages with a declaration part.

OK, I learned something more tonight :cool: