Dynamischen Wert eintragen

  • Dynamischen Wert eintragen

    Hallo liebe Entwickler...

    Ich bräuchte mal wieder kurz eure Hilfe. Es geht um einen content translator für Tapatalk, welcher soweit auch funktioniert. In unserem Forum wird zwischen Zitaten und Erwähnungen unterschieden. Nun möchte ich die Erwähnungen korrekt in meiner App angezeigt bekommen, und zwar so:

    [Blockierte Grafik: http://abload.de/img/bildschirmfoto2013-05a3uct.png]

    Das funktioniert mit folgendem Code:

    Brainfuck-Quellcode

    1. #pragma mark - Mentions
    2. NSRange mentionRange = [string rangeOfString:@"[mention][url=" options:NSCaseInsensitiveSearch];
    3. while (mentionRange.location != NSNotFound) {
    4. NSScanner *scanner = [NSScanner scannerWithString:string];
    5. [scanner setScanLocation:mentionRange.location + mentionRange.length];
    6. [scanner scanUpToString:@"]Erwähnung von " intoString:NULL];
    7. NSUInteger location = [scanner scanLocation] + 11;
    8. [scanner scanUpToString:@"[/url]" intoString:NULL];
    9. NSUInteger length = [scanner scanLocation] - location;
    10. NSString *username = [string substringWithRange:NSMakeRange(location, length)];
    11. location = mentionRange.location;
    12. mentionRange = NSMakeRange(location, [scanner scanLocation] + 6 - location);
    13. string = [string stringByReplacingCharactersInRange:mentionRange withString:[NSString stringWithFormat:@"Erwähnung von %@:\n----------------------------------------\n", username]];
    14. mentionRange = [string rangeOfString:@"[mention][url=" options:NSCaseInsensitiveSearch];
    15. }
    16. string = [string stringByReplacingOccurrencesOfString:@"[MENTION=198571]" withString:@"Erwähnung von:\n----------------------------------------\n" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [string length])];
    17. string = [string stringByReplacingOccurrencesOfString:@"[/mention]" withString:@"\n----------------------------------------\n" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [string length])];
    Alles anzeigen


    Das Problem ist, dass sich die Mention ID verändert, sodass es ohne hardcode so aussieht:

    [Blockierte Grafik: http://abload.de/img/bildschirmfoto2013-053pava.png]

    Wie kann ich das machen, dass da jeder Wert so angenommen wird, dass es in der App korrekt aussieht?

    Viele Grüsse,

    Stephan

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von Thaddel ()

  • Problem gelöst:

    Quellcode

    1. NSRange mentionRange = [string rangeOfString:@"[mention=" options:NSCaseInsensitiveSearch];
    2. while (mentionRange.location != NSNotFound) {
    3. NSScanner *scanner = [NSScanner scannerWithString:string];
    4. [scanner setScanLocation:mentionRange.location + mentionRange.length];
    5. [scanner scanUpToString:@"]" intoString:NULL];
    6. NSUInteger location = mentionRange.location;
    7. mentionRange = NSMakeRange(location, [scanner scanLocation] + 1 - location);
    8. string = [string stringByReplacingCharactersInRange:mentionRange withString:@"Erwähnung von: "];
    9. mentionRange = [string rangeOfString:@"[mention=" options:NSCaseInsensitiveSearch];
    10. }
    11. string = [string stringByReplacingOccurrencesOfString:@"[/MENTION]" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [string length])];
    Alles anzeigen