如何从目标c中的数组数组中删除字符串中的括号?

时间:2016-12-16 09:58:17

标签: objective-c arrays

// Form the query.
        NSString *query = [NSString stringWithFormat:@"select firstTimeStamp from activityTimeStamp where userId=\"%@\" And buddyId=\"%@\"",[PFUser currentUser].username,buddyId];    
        // Get the results.
        if (self.arrTimeStampInfo != nil) {
            self.arrTimeStampInfo = nil;
        }
        // Getting Data into Array
        self.arrTimeStampInfo = [[NSArray alloc] initWithArray:[self.dbManager loadDataFromDB:query]];

       // Get the results.
    if (self.arrTimeStampInfo != nil) {
        self.arrTimeStampInfo = nil;
    }

    NSLog(@"Array containing records%@", self.arrTimeStampInfo);
and it prints (    (1111132324)   ) 
    NSString *string = [_arrTimeStampInfo objectAtIndex: 0];

当我打印字符串时,它就像(1111132324),我想删除那些仅需要字符串中的数字的括号?任何线索都将受到高度赞赏。

2 个答案:

答案 0 :(得分:0)

我使用此代码

 $username = "root";
 $password = "";
 $hostname = "localhost"; 

 //connection to the database
 $dbhandle = mysql_connect($hostname, $username, $password) 
    or die("Unable to connect to MySQL");

if ($dbhandle) {
     echo 'conected';
} else {
      echo 'not conected WITH DATABASE';
}

mysql_select_db('data');

$indentdata= "INSERT INTO indentname ( deskno, fileno, indentdate, receivedate, indentorid, projectleaderid, division, estimatedcost, convertedcost, item, projectno, cprojectno, projectname, budgethead, cashcode, nature, is_delete) VALUES ( '".$_POST['deskno']."','".$_POST['fileno']." ', '".$_POST['indentdate']." ', ' ".$_POST['receivedate']." ', ' ".$_POST['indentorname']." ' , ' ".$_POST['projectleader']." ' , ' ".$_POST['estimatedcost']." ', ' ".$_POST['convertedtedcost']." ' , ' ".$_POST['item']." ', ' ".$_POST['projectno']." ', ' ".$_POST['conprojectno']."',' ".$_POST['projectname']." ',' ".$_POST['budgethead']." ',' ".$_POST['cashcode']." ',' ".$_POST['nature']." ',0 )";
       mysql_query($indentdata);

我得到输出:

enter image description here

正如您所看到的那样,当我打印数组时,它会在括号中提供输出'('和')'。如果我只打印一个字符串的单个元素,这里没有大括号。

正如你所说,你有阵列中的数组,试试这个

 NSArray *array = @[@"1111132324"];
 NSLog(@"array : %@", array);
 NSLog(@"array[0] : %@", array[0]);

见输出:

enter image description here

您可以将字典或数组的层次结构或数组字典的混合(无关紧要)扩展到n次。

每个键(对于dict)/ index(对于数组)必须在该层次结构级别。获取数据的方式是从上层到下层。

字典

NSArray *arrayOuter = @[@"1111132324"];
NSArray *arrayInner = @[arrayOuter];

NSLog(@"array : %@", arrayInner);
NSLog(@"array[0] : %@", arrayInner[0]);
NSLog(@"array[0] : %@", arrayInner[0][0]);

for mix dict-arr

dict[@"key1"][@"key2"]...[@"keyN"] 

用于mix array - dict

//upper object must be dictionary so start with key.
dict[@"key1"][0][@"key"]..[@"keyN"] or object index.

注意:键和索引的顺序取决于该层次结构中的对象。

答案 1 :(得分:-1)

  // Getting Data into Array
    self.arrTimeStampInfo = [[NSArray alloc] initWithArray:[self.dbManager loadDataFromDB:query]];
    NSArray* firstItem = [self.arrTimeStampInfo objectAtIndex:0]; 
    NSString* string1 = [firstItem objectAtIndex:0];
    NSLog(@"Array containing records%@", string1);
    NSInteger a=[string1 intValue];
  NSLog(@"time stamp finally we got = %ld",a);