How to remove the junk characters from string in aes128 decryption [closed] - iphone

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
The problem is encryption in server side they are using ISO10126d2Padding and decryption is happening but after decryption it is showing some junk values anyone please help remove that :
ACTUAL RESULT = india ismy
*DECRYPTED VALUE = India ismyg~²t

I will not say that this is the best way to remove unwanted characters from NSString but i did this ... and it is great.
NSString * str = #"your string";
NSMutableString * newString;
int j = [str length];
for (int i=0; i<j; i++) {
if (([str characterAtIndex:i] >=65 && [str characterAtIndex:i] <=90) || ([str characterAtIndex:i] >=97 && [str characterAtIndex:i] <=122) ||[str characterAtIndex:i] == 32 ) {
[newString appendFormat:#"%c",[str characterAtIndex:i]];
}
}
//([str characterAtIndex:i] >=65 && [str characterAtIndex:i] <=90) this is ASCII limit for A-Z
//([str characterAtIndex:i] >=97 && [str characterAtIndex:i] <=122) this is ASCII limit for a-z
//and [str characterAtIndex:i] == 32 is for space.
Now, print new string
NSLog(#"%#",newString);
let me know if it is woking for you!
Thank You!

Related

how to convert NSMutable array with NSNumber into strings [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
my array is containing ids they are in NSNumber how can i convert them in string my array is like below
1494447926,
1537064431,
1545735176,
1574825141,
1604834983,
1829486110,
1838260338,
1846543841,
1850381039,
100000039842949,
100000077723868,
100000103091995,
100000126558358,
100000130915431,
100000139092102,
100000157330187,
100000157646688,
100000197141710,
100000243178639,
100000249947961,
please give me sample code to convert it to string
First of all array can not store integer. It must be in NSNumber or it is in NSString itself.
In either of the case you can create a long string by appending them,
NSString *string=[yourArray componentsJoinedByString:#","];
Or, if you want each value as string then you need to create that much string and then access them.
NSArray *numbersToStrings=[NSArray new];
for(id element in yourArray){
[numbersToStrings addObject:[NSString stringWithFormat:#"%#",element];
}
Here numbersToStrings contains all the values as string.
Use this.
NSString *str = [NSString stringWithFormat:#"%i",number];
for(int i=0;i<[arr count];i++){
str = [NSString stringWithFormat:#"%d",[arr objectAtIndex:i]];
[newArr addObject:str];
}
NSString *str = [NSString StringWithFormat:#"%d",1494447926];
You can use stringWithFormat
NSString *str = [NSString stringWithFormat:#"%d", [YourArray objectAtIndex:index]];
You cannot store integers into an array. If you are getting this response from server each would be NSNumber. You can type cast that to NSString.
do this
NSArray *ll=[NSArray arrayWithObjects:#"1",#"2",#"3", nil];
NSString *strinList=[NSString stringWithFormat:#"%#",[ll objectAtIndex:0]];
try this ,if you required other help ,i am here .
Only Search on Google - convert int to NSString , multiple Answer are displayed
by the way, your need to use only [NSString stringWithFormat:#"%d",YourIntValue]
for (int i=0; i < MyArray.count; i++)
{
NSString * String =[NSString stringWithFormat:#"%d", [MyArray objectAtIndex:i]];
NSLog(#"%#",String);
}

Anniversary from contacts in iPhone [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm able to get birth dates from contacts but not the anniversary dates on iPhone. I have used KABPersonAnniversaryLabel but it is giving an error.
This code will fetch anniversary for all contacts,
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
for (CFIndex i = 0; i < CFArrayGetCount(people); i++) {
ABRecordRef person = CFArrayGetValueAtIndex(people, i);
ABMultiValueRef anniversaries = ABRecordCopyValue(person, kABPersonDateProperty);
NSString *anniversaryLabel;
for (CFIndex j=0; j < ABMultiValueGetCount(anniversaries); j++) {
anniversaryLabel = (NSString*)ABMultiValueCopyLabelAtIndex(anniversaries, j);
if([anniversaryLabel isEqualToString:(NSString *)kABPersonAnniversaryLabel])
{
NSDate *anniversaryDate=(NSDate *)ABMultiValueCopyValueAtIndex(anniversaries, j);
NSLog(#"%#",anniversaryDate);
}
}
CFRelease(anniversaries);
}
CFRelease(addressBook);
CFRelease(people);

Fetch different data types values from string and separate them [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am using QR code and after scanning getting username, eventtitle and ticketcode. I need to get these values separately in three different strings, so that i can save them in sqlite. I want to know only how to do this separation, saving is i can do.
Thanks in advance.
- (void)saveData {
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat: #"INSERT INTO CONTACTS (name, address, phone) VALUES (\"%#\", \"%#\", \"%#\")", #"NameString", #"Address", #"Phone"];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSLog(#"Success");
} else {
NSLog(#"Failed");
}
sqlite3_finalize(statement);
sqlite3_close(contactDB);
}
}
Note
If you post what type of string you are getting, i will add how exactly you have to split it.
Below is example how you can split
NSArray arrResult = [str componentsSeparatedByString:#"-"];
Or By Character set
NSString* str = #"A string with newlines in it";
NSArray *arrTemp = [str componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
you can use componentsSeparatedByString
NSString *str = #"userName:Password:etc";
NSArray* parts1 = [str componentsSeparatedByString:#":"];
NSLog(#" [[parts1 objectAtIndex:0] integerValue]=%d", [[parts1 objectAtIndex:0] integerValue]);
//the output will be: username for index 0, and so on

Transforming NSMutableArray values [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I've been looking for this, but can't find the answer.
I have an NSMutableArray with values who_1, what_2, where_3 etc.
I want to transform this into who, what, where etc.
I already have the value of the integer as a variable, and _ is just a string.
What steps should I take to have all these arrayvalues transformed?
NSArray * arrB = [[NSArray alloc]initWithObjects:#"apple_a",#"ball_b",#"cat_c",#"doll_d",nil];
NSMutableArray * arrA = [[NSMutableArray alloc]init];
for(NSString *strData in arrB)
{
NSArray *arr = [strData componentsSeparatedByString:#"_"];
[arrA addObject:[arr objectAtIndex:0]];
}
and this would be your output
arrA:(
apple,
ball,
cat,
doll
)
You need to apply logic for that, You cant find answers to tricky Questions :)
You need to run a loop.
Separate string with '_'
Loop
for(NSString *s in ary)
{
NSArray *a = [s componentsSeparatedByString:#"_"];
[anotherArray addObject:[a objectAtIndex:0]];
}
and update your array..
Following might help you -
NSRange range = [string rangeOfString:#"_"];
NSString *finalString = [originalString substringToIndex:range.location];
you can have this in loop.
Or you can go for componentSeperatedByStrings.
This might help you
NSMutableArray *tmpAry = [[NSMutableArray alloc] init];
for(NSString *_string in _StringAry)
{
NSCharacterSet *charSet = [NSCharacterSet characterSetWithCharactersInString:#"_0123456789"];
_string = [[_string componentsSeparatedByCharactersInSet:charSet] componentsJoinedByString:#""];
[tmpAry addObject: [[_string copy] autorelease]];
}
NSLog(#"%#", tmpAry); // Gives the modified array
[tmpAry release];

How enter in '.' first and then number in text of texfield? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want enter float value in text field like as '.35'or '35' but not as '0..3678'.I want to restrict on enter of double dots. How do that?
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:
(NSRange)range replacementString:(NSString *)string{
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber* myNumber;
NSString* myString = [textField.text stringByReplacingCharactersInRange:range withString:string];
range = NSMakeRange(0, [myString length]);
[numberFormatter getObjectValue:&myNumber forString:myString range:&range error:nil];
if (([myString length] > 0) && (myNumber== nil || range.length < [myString length])) {
return NO;
}else {
return YES;
}
}
I use above code for enter numeric value but it can't enter first dot/point and then number. What is error in above function?
int dots = 0;
for (int i = 0; i<[string length]; i++) {
char test = [string characterAtIndex:i];
if (test == '.') dots++;
}
if (dots > 1) {
return NO;
}
return YES;
Just check if the character is the first character, check if it is a dot, and if it is, pass 0. as the initial two characters in myString.