Empty Character while looping - swift

Hey i have a string which printed gives the following: BBBKKKKJJJJJJGGG​G
If I use this code:
for (index,character) in vin.characters.enumerated(){
print(character)
vinTextFields[index].text = String(character)
}
to split it into some textFields the index is out of range. This is because the for loop inserts an empty character.
This is what the print(character) gives me back.
I really not get why this empty line appears.

I tested it, it seems there is a character that is not printable between the last two 'G'.
I think you copied and pasted it from somewhere. That's how that character made it there.
Remove the last two 'G' and type them again and you will be good to go. I tested that too.

Related

Last string appears at beginning of line in formatted output

Has anyone any idea why the following would format itself in a weird way? In several years I've had no problem with creating simple text output but this problem has me baffled.
I'm using the line
print "$BC,$Ttl,$FN,$SN,$Finalage,$OurLoc,$OurDT,$FinalPC\n";
Every value is a simple text string on which I've run "chomp" to remove return characters.
I would expect the output to look like the following:
*DD10099999,,Information Services,Guest Ticket 2,41,C G,03/11/2020,NE8 9BB*
$BC is the first item and $FinalPC is the postcode at the end.
Instead I get:
*,NE8 9BB99, ,Information Services,Guest Ticket 2,41,C G,03/11/2020*
The final item has somehow moved to the beginning of the line and overwritten the first item. This is happening consistently on every line of my screen and text file output and I'm completely stumped as to why. The data is read from a text file and compared with database output which is also simple text. There are no occurrences of \b anywhere in my code. Why would a backspace character get into it?
The string in $OurDT ends with a carriage return, which causes your terminal to home the cursor. Presumably, the value of $OurDT came from a Windows file read on a unixy machine.
One option is to fix the file (e.g. by using the dos2unix utility).
Another is to accept both CRLF and LF as line endings (e.g. by using s/\s+\z// instead of chomp).

Swift Thai Localization Problems

There seems to be a problem with the String library that apple uses.
Here's my Localizable.strings
"error_failed_to_retrieve_certificate" = "เกิิดผิดพลาดในการกู้คะแนน";
Here's how I set it to any view
anyView.text = return NSLocalizedString("error_failed_to_retrieve_certificate", comment: "")
But somehow the string that is being displayed gets warped, when it gets displayed, (the second character becomes different.
Here's what it looks like too when I search it using the Project Search.
But on the Strings it looks different (notice the third character)
Here's one image that is side by side
Note that I don't know any Thai.
It seems like that your string has an extra ิ (U+0E34 THAI CHARACTER SARA I) in it. The character before that, กิ, is already two code points combined - ก (U+0E01 THAI CHARACTER KO KAI) and ิ, so the extra ิ got displayed alone. I would say it's an Xcode bug.
I've removed the extra character here:
เกิดผิดพลาดในการกู้คะแนน
Copy and paste that and it should be fine.
You need to check if you have unique key "error_failed_to_retrieve_certificate". this key value is unique.

How to join an array of strings?

I am having problems attempting to return elements of a String array line by line within a textView. I have indeed used the special carriage return character in my code sequence to return elements of the array on separate lines. However, I have not been able to succeed thus far. Here is a code snippet of what I typed:
txtViewQuestionStatus.text = "\(numCorrect) correct Answers, However these are the questions answered INCORRECTLY: \(model.incorrectItems())\n" //Have text view present number of correct answers and list incorrect Questions line by line.
What could I be doing wrong in my source code? Thanks!
What is model.incorrectItems() returning? Can you post that part of your code? If it returns an array of strings you can join them like so:
"... INCORRECTLY: \(model.incorrectItems().joinWithSeparator("\n"))\n"

Perl Pattern Matching extracting inside brackets

I really need help with coming up with the pattern matching solution...
If the string is <6>[ 84.982642] Killing the process
How can I extract them into three separate strings...
I need one for 6, 84.982642, and Killing the process..
I've tried many things but these brackets and blank spaces are really confusing me and I keep getting the error message
"WARNING: Use of uninitialized value $bracket in pattern match..."
Is there anyway I can somehow write in this way
($num_1, $num_2, $name_process) = split(/[\-,. :;!?()[\]{}]+/);
Not sure how to extract these..
Help Please?
Thank you so much
Assuming the input is in $_
($num_1, $num_2, $name_process) = /^<(\d+)>\[([^\]]+)\]\s+(.*)$/;
This assumes the first token in the angle brackets is always a number. For a little more generality use
($num_1, $num_2, $name_process) = /^<([^>]+)>\[([^\]]+)\]\s+(.*)$/;
Explanation:
<([^>]+)> - a left-angle-bracket followed one or more characters that are not a right angle-bracket, followed by a right-angle bracket.
\[([^\]]+)\] - a left-bracket followed by one or more characters that are not a right bracket, followed by a right bracket
\s+(.*) - one or more spaces, then capture everything starting with the first non-blank after that.

lex/yacc won't recognize a string (syntax error)

Hi i'm trying to let lex/yacc split this string
table subwayLines:int[3]
into tokens of table, subwayLines, int[3] with the [3] optional(i.e. int or int[3])
everything is fine until i try to recognize the "int",
so this is what i did in lex
[A-Za-z0-9\[\]]+ { /* column property*/
yylval.sval = (char *)strdup(yytext);
char* temp=yylval.sval;
return STRING;
}
i know the problem is in
[A-Za-z0-9\[\]]+
because when i changed it to
[A-Za-z]+("[")?+[0-9]+("]")?+(",")?
it works except I still can't go without the "[" or "]", for example, if i wrote this in my string:
table subwayLines:int
then it gives me a syntax error
so does anyone knows how to do change it? thanks
To make the [3] optional, this will not work:
[A-Za-z]+("[")?+[0-9]+("]")?+(",")?
You've made only the square brackets optional, but not the number in between. You need something like
[A-Za-z]+("["[0-9]+"]")?
I.e. the entire square-bracketed part is optional.
Also the combination (REGEX)?+ doesn't make much sense (the ?+ part of it). It's equivalent to (REGEX)*, since you're effectively saying that (REGEX) is optional, one or more times, which is like zero or more.
(Not sure why you have the optional comma in the second example; the first one doesn't recognize a comma and it's not shown in your example input.)