小编Tom*_*lly的帖子

来自NSArray的NSMutableArray

我有以下代码,我想使用NSMutable数组而不是NSArray你能告诉我如何加载NSMutable数组,因为当前的方法不起作用.

-(void) whatever{
NSData *htmlData = [[NSString stringWithContentsOfURL:[NSURL URLWithString: @"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *titles  = [xpathParser search:@"//h3"]; // get the page title - this is xpath     notation
TFHppleElement *title = [titles objectAtIndex:0];
NSString *myTitles = [title content];

NSArray *articles  = [xpathParser search:@"//h4"]; // get the page article - this is xpath     notation
TFHppleElement *article = [articles objectAtIndex:0];
NSString *myArtical = [article content];
Run Code Online (Sandbox Code Playgroud)

我试过了 :

NSMutableArray *titles  = [xpathParser search:@"//h3"];
Run Code Online (Sandbox Code Playgroud)

但它确实加载了这些值?

objective-c nsmutablearray nsarray ios

15
推荐指数
3
解决办法
3万
查看次数

如何在Powershell中使用正则表达式选择“捕获”代码块?

我正在尝试分析许多目录中的许多Powershell脚本,并且我想将任何Catch代码块拉到列表/变量中。

我正在尝试编写正则表达式以选择以下格式的任何块

    Catch 
        {
        write-Host "Function:",$MyInvocation.MyCommand,"Failed with exception:" "Error"
        write-Host "Exception: $_" "Error"
        throw "Exception: $_"
        }

Run Code Online (Sandbox Code Playgroud)
    Catch{
        write-Host "Function:",$MyInvocation.MyCommand,"Failed with exception:" "Error"
        write-Host "Exception: $_" "Error"
        throw "Exception: $_" }
Run Code Online (Sandbox Code Playgroud)
Catch {write-Host "Function:",$MyInvocation.MyCommand,"Failed with exception:" "Error"
        write-Host "Exception: $_" "Error"
        throw "Exception: $_"}

Run Code Online (Sandbox Code Playgroud)

基本上在任何地方都有一个接在{}之后的catch,忽略单词“ Catch”和花括号之间以及花括号之后的换行符,忽略大小写。

我也希望返回{}之间的全部内容,以便我可以对其进行一些其他检查。

我设法弄出的最好的是:


\b(\w*Catch\w*)\b.*\w*{\w.*}
Run Code Online (Sandbox Code Playgroud)

如果全部在一条线上,则将匹配。

我将在powershell中进行此操作,因此将非常感谢.net或powershell类型的正则表达式。

谢谢。

regex powershell parsing

3
推荐指数
1
解决办法
38
查看次数

为什么我在Powershell和C#之间得到不同的结果

我有一种将日期时间转换为DOS格式的方法

它最初是用C#编写的,但是我已经将其转换为powershell。

两者的相同输入将返回不同的结果。我正在努力寻找原因。

Powershell方法

Function ConvertTo-DOSDate {
    Param(
        [DateTime]$dateTime

    )

    Process {
        Try {

            [int] $ret = (($dateTime.Year - 1980) -band 0x7F);
            $ret = ($ret -shl 4) + $dateTime.Month;
            $ret = ($ret -shl 5) + $dateTime.Day;
            $ret = ($ret -shl 5) + $dateTime.Hour;
            $ret = ($ret -shl 6) + $dateTime.Minute;
            $ret = ($ret -shl 5) + ($dateTime.Second / 2); # only 5 bits for second, so we only have a granularity of 2 sec.
            return  [uint32] $ret;

        }
        Catch { …
Run Code Online (Sandbox Code Playgroud)

c# powershell datetime bit-shift

2
推荐指数
1
解决办法
74
查看次数

NSString导致EXC_BAD_ACCESS,字符串太长了?

当我的应用程序到达此时,我收到EXC_BAD_ACCESS

NSString *nameData = nameTextField.text;
NSString *emailData= emailTextField.text;
NSString *phoneData = phoneTextField.text;
NSString *serviceData =    serviceTextView.text;

NSString *post = [NSString stringWithFormat:@"email_address=&contents=&form_identifier=538b7271-df83-41f5-84b0-db0fed518ade&form_type=1&empty_form_msg=Please%20fill%20in%20something%20before%20submitting.&1_1_10_40_First%2BName=%@&2_1_20_30_Last%2BName=&3_1_25_25_Company=&4_1_30_999_Email=%@&5_1_40_10_Phone=%@&6_1_50_0_Address%2B1=&7_1_60_-10_Address%2B2=&8_1_70_-20_City=&9_3_80_-30_County=&10_3_90_-40_Postcode=&11_2_100_-50_Comments=%@&submit=Send",nameData,emailData,phoneData,serviceData];
Run Code Online (Sandbox Code Playgroud)

这是因为这个字符串中的数据太长了吗?

iphone exc-bad-access objective-c nsstring

0
推荐指数
1
解决办法
134
查看次数