• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Find text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Find text


  • Subject: Re: Find text
  • From: Artyom Loenko <email@hidden>
  • Date: Fri, 20 Apr 2012 15:31:39 +0400

Hi,

Regexp can help. As a example:

NSString *text = 
        @"SMART Disk Hitachi HTS545050B9SA02 (100826PBL40017J9VZTV): 32 C \n\
        SMB NORTHBRIDGE CHIP DIE: 51 C \n\
        SMC BATTERY: 35 C \n\
        SMC BATTERY POSITION 2: 35 C \n\
        SMC BATTERY POSITION 3: 32 C \n\
        SMC BATTERY POSITION 4: 37 C \n\
        SMC CPU A DIODE: 52 C \n\
        SMC CPU A PROXIMITY: 48 C \n\
        SMC LEFT PALM REST: 32 C \n\
        SMC MAIN HEAT SINK 2: 48 C \n\
        SMC MAIN HEAT SINK F: 48 C \n\
        SMC NORTHBRIDGE POS 1: 46 C \n\
        Smart Battery bq20z451 (19457): 35 C";

        

        NSString *text_random = 
        @"SMB NORTHBRIDGE CHIP DIE: 51 C \n\
        SMC BATTERY: 35 C \n\
        SMC BATTERY POSITION 2: 35 C \n\
        SMC BATTERY POSITION 3: 32 C \n\
        SMC BATTERY POSITION 4: 37 C \n\
        SMART Disk Hitachi HTS545050B9SA02 (100826PBL40017J9VZTV): 32 C \n\
        SMC CPU A DIODE: 52 C \n\
        SMC CPU A PROXIMITY: 48 C \n\
        SMC LEFT PALM REST: 32 C \n\
        SMC MAIN HEAT SINK 2: 48 C \n\
        SMC MAIN HEAT SINK F: 48 C \n\
        SMC NORTHBRIDGE POS 1: 46 C \n\
        Smart Battery bq20z451 (19457): 35 C";

        

        NSRegularExpression *regex = [NSRegularExpression
                                      regularExpressionWithPattern:@"([^\n].*Disk.*\n+)"
                                      options:NSRegularExpressionCaseInsensitive
                                      error:nil];
        NSTextCheckingResult *textCheckingResult = [regex firstMatchInString:text options:0 range:NSMakeRange(0, text.length)];
        NSLog(@"found: '%@'", [text substringWithRange:[textCheckingResult rangeAtIndex:1]]);

        

        textCheckingResult = [regex firstMatchInString:text_random options:0 range:NSMakeRange(0, text_random.length)];
        NSLog(@"found: '%@'", [text_random substringWithRange:[textCheckingResult rangeAtIndex:1]]);

-
 Artyom Loenko

On Apr 20, 2012, at 3:12 PM, Javi Pérez wrote:

Hi, 

I have this text in a variable

SMART Disk Hitachi HTS545050B9SA02 (100826PBL40017J9VZTV): 32 C
SMB NORTHBRIDGE CHIP DIE: 51 C
SMC BATTERY: 35 C
SMC BATTERY POSITION 2: 35 C
SMC BATTERY POSITION 3: 32 C
SMC BATTERY POSITION 4: 37 C
SMC CPU A DIODE: 52 C
SMC CPU A PROXIMITY: 48 C
SMC LEFT PALM REST: 32 C
SMC MAIN HEAT SINK 2: 48 C
SMC MAIN HEAT SINK F: 48 C
SMC NORTHBRIDGE POS 1: 46 C
Smart Battery bq20z451 (19457): 35 C

and I want to get the line contain "Disk" (not always the first line)

After search I just find ways to get an offset as much
Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users This email sent to email@hidden
  • Follow-Ups:
    • RE: Find text
      • From: Javi Pérez <email@hidden>
References: 
 >Find text (From: Javi Pérez <email@hidden>)

  • Prev by Date: Find text
  • Next by Date: RE: Find text
  • Previous by thread: Find text
  • Next by thread: RE: Find text
  • Index(es):
    • Date
    • Thread