Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Friday, May 10, 2013

Get substring from an NSString in Objective-C

In Objective-C / Cocoa to grab a substring from an NSString based on beginning and ending characters is easy. This is helpful if you want to parse HTML, JSON, or a REST statement returning. See below:


 NSString *sStr = [NSString stringWithFormat:@"%@", assetGroups[indexPath.row]];
 NSString *name= [[[[sStr componentsSeparatedByString:@"Beginning Char(s)"] objectAtIndex:1] componentsSeparatedByString:@"End Char(s)"] objectAtIndex:0]; 
 NSString *newString = [NSString stringWithFormat:@"%@", name];

Tuesday, March 12, 2013

Convert a String/Text into an Integer Array in JS

In Java sometimes you have a long string of numbers or text delimited by a space or comma. This code below converts it simply into an Integer array. You can change your delimiter under split(" "); I've set it to space for default:

 String[] parts = wholef[0].split(" ");
 int[] intwholef= new int[parts.length];

 for(int n = 0; n < parts.length; n++) {
    intwholef[n] = Integer.parseInt(parts[n]);
  }

Generating "Always On Top" NSWindow in macOS across all detected displays

Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift  Langues, you m...