Note that there are some explanatory texts on larger screens.

plurals
  1. POperl - Split string by methods within the strings
    primarykey
    data
    text
    <p>I have two questions:</p> <p>First, how can I split the following string into individual strings split by the methods within the string? I tried using regex, but was unsuccessful.</p> <pre><code>$objc = "- (void)method { NSLog(@"method"); if (1 == 1) { //blah blah blah } } - (id)otherMethodWithProperty:(NSString *)property { NSLog(@"otherMethodWithProperty:"); return property; } -(id) methodWithMoreProperties: (id)property Property2:(UIView *)property2 Property3:(NSString *)property3 { id view = property; if (view) { NSLog(@"%@", view); } return view; }" </code></pre> <p>Second question is after splitting into individual strings, is it possible to grab each property and add it within the respective string? For example:</p> <p>I take the string:</p> <pre><code>"-(id) methodWithMoreProperties: (id)property Property2:(UIView *)property2 Property3:(NSString *)property3 { id view = property; if (view) { NSLog(@"%@", view); } return view; }" </code></pre> <p>grab the properties "property, property2, property3" and add them within the string after the first "{" and before the last "}":</p> <pre><code>"-(id) methodWithMoreProperties: (id)property Property2:(UIView *)property2 Property3:(NSString *)property3 { NSLog(@"%@\n%@\n%@", property, property2, property3); id view = property; if (view) { NSLog(@"%@", view); } return view; NSLog(@"FINISH: %@\n%@\n%@", property, property2, property3); }" </code></pre> <p>I've been googling and testing code for hours and I've only managed, using regex, to get the method name </p> <blockquote> <p>-(id) methodWithMoreProperties:</p> </blockquote> <p>and add it within the string, but haven't been able to grab the properties themselves and add them after the first { and before the last }</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload