Whether a blank string should be localized in ios - ios

I have a label which will show the text which I have added using the below code
m_label = [[[NSString stringWithFormat:#"%d",retValue]stringByAppendingString:#" "]stringByAppendingString:NSLocalizedString(#"DAYS",nil)];
So here the text will be displayed in this format: 10(space)days.
I have localised the "days" string,I want to know whether we should localise a space or blank string,
Regards
Ranjit

I think this depends on the languages you are targeting, in the end.
I don't see any particular risks with the expression "10 days", in almost any language I know the number of days would be separated from the word "days" by a space. Of course, I don't know all the languages in the world.
Just an opinion.

Why not simply:
m_label = [NSString stringWithFormat:#"%d %#",
retValue, NSLocalizedString(#"DAYS",nil)];
If the need arises, you can localize the format string. That way, you will not only get flexibility on whitespace, but also e.g., on ordering: putting "DAYS" before their count.

Related

reg expressions - dates and words

Write a regular expression for the following:
A regular expression that finds dates in files. Correct dates must be in the format
DD-MM-YYYY and within the years 1900s and 2000s. No need to enforce the
correct maximum number of days in a month.
For example, within the following list:
10-02-2011
, 6-Feb-2016
, 8-5-2016
, 07-08-1966
, 32-05-2022
only 10-02-2011 and 07-08-1966 are valid dates.
A regular expression that accepts any of the following answers for the question
“What are 5, 6 and 14?”
numbers
They’re numbers
They are numbers
According to your question, the regex pattern must match any date between 1900 and 2000, is that correct? If it is that what you want, this is the pattern you need:
(3[0-1])|([0-2][0-9])-((0[0-9])|(1[0-2]))-(19\d{2})|2000
The year group will match any year from 1900 to 2000, let me know if you find any error on this pattern, or give me some entries that this pattern should've matched...
Hope I have helped!

Substring specific integer from string

I have google some related questions, but unfortunately didn't find answer.
I have string like 2016-07-22, i need to get an integer 07, evaluate it to 7 and save.
Of course, this is date, therefore it will change every time, so i cant suppose that year always will be 2016. I need to get string after 5th symbol up to 8th.
Is there any easy way to achieve that? Thanks.
If it's always that section of the string, you can use NSMakeRange(5, 2) and substringWithRange to pick out the month.
After you have "07", conversion is just a case of asking the string for its integerValue.
The "save" part depends entirely on where you want to save it.
Here is just one way (I can think of at least 3 other ways):
NSString *str = #"2016-07-22";
NSArray *elements = [str componentsSeparatedByString:#"-"];
NSAssert([elements count] == 3, #"Ahhh!");
NSInteger month = [elements[1] integerValue];

If equation with three possible outputs

I've looked for this solution, but it currently eludes me:- Cell AG15 is the output message cell. If there is a date in A15, I want it to read "Loaded", If there is a date in cells A15 AND M15, I want it to read "Work in Progress", If there is a date in cells A15, M15 AND N15, I want it to read "Waiting Quote"....I seem to have hit a blind spot - I'm sure it's simple Grrrrr
I guess you can start with:
=IF(A15<>"",IF(M15<>"",IF(N15<>"","Waiting Quote","Work in Progress"),"Loaded"),"")
Assuming that those cells are empties or contain valid dates (valid for your task, es. M15 < N15). If you have to check if a data is actually a date, you can use the VBA function IsDate().
Or if you want to work the other way back i.e. as long as there is a date in N15 you don't need dates in the other two to get "Awaiting quote"
=IF(N15="",IF(M15=,"",IF(A15="","","Loaded"),"Work In Progress"),"Awaiting Quote")

Simple convert NSString with comma to float or double.

I have a screen where the user can enter some information. It shows a decimalPad. According to the user locale, I know the decimalPadwill show commaor period, or even something else.
Therefore, my database will contain NSStrings stored from the users, although, some of them will have comma, like 5,4, or period, as in 5.4. The problem is that I need to do some math with these values, and I can't find a pattern to convert them.
Lets say the NSStringhas a comma, as in 5,4. I can easily convert that to a floatusing:
NSNumberFormatter *commas = [NSNumberFormatter new];
commas.numberStyle = NSNumberFormatterDecimalStyle;
NSLocale *commaLocale = [[NSLocale alloc] initWithLocaleIdentifier: #"br_PT"];
commas.locale = commaLocale;
NSString *string = #"5,4";
float testFloat = [[commas numberFromString:string] floatValue];
I correctly get the result 5.4, and can go on with my math calculations. But for instance, if the number was saved by an US user, the NSString would be 5.4, and I wouldn't get the right result using this code. Even if I get user current locale, it doesn't help me, since the user will get values stored all around.
Anyway, I'm a little confused with this. How could I simply create a pattern to deal with this?
I don't want to work with the string, as in stringByReplacingOccurences..., anyway, at least if I can avoid that.
If you want to use the value as a number, you should store the value as a number in your database. NSNumber is a perfect object for that and with your method you can get correct value. When you show the value again to the user you should convert the NSNumber again with NSNumberFormatter. Everything else will be a workaround and have negative impact. Even with stringByReplacingOccurences... you have the risk that somebody uses thousand-dots or commas...

NSDateFormatter date format string

I have an odd issue with an NSDateFormatter, I am passing the following string as a date format "dd/MM/yy"
If I enter 50 for the year I get a conversion to 1950 however anything below that for instance 49 results in 2049. Any ideas how I can remedy this?
Many thanks.
It sounds like you'll need to force a four digit response (or programmatically prepend two digits of "19") to wherever you're drawing your string from. Lots of people are using dates in the near to mid-term future like "12/21/12" (end of the Mayan Calendar era) so it's natural that a 2 digit year assumes 2000+ for digits 1-50 and 1999- for digits (50-99).
I'm also seeing a number of Google hits on the keyword terms "NSDateFormatter" & "century", b.t.w.

Resources