Cocos2D: CCLabelTTF won't preserve ending whitespace. - cocos2d-iphone

I need to have a CCLabelTTF print spaces at the end of a string, but they won't. I can log the string and clearly see that the spaces at the end are preserved by highlighting the log.
I've tried appending a decimal ascii non-breaking space, but it shows up as a different character. The font I'm using is Monaco.

I figured it out. Instead of appending #" " I appended the unicode value U+00A0 like this:
labelPieceObj = [labelPieceObj stringByAppendingString:#"\u00A0"];

Related

Need to remove whitespace from file using regular expression

I have a huge file around half a gig and the file has records shown below:
44 ,1577,23GRE ,GREASE THE ENGINE
44 ,1577,23GRE ,GREASE THE ENGINE
44 ,1577,24GRE ,GREASE THE WHEELS
I want to remove white spaces between the the commas and whitespaces after content "GREASE THE ENGINE" and convert the file as shown below using vi:
"44","1577","23GRE","GREASE THE ENGINE"
"44","1577","23GRE","GREASE THE ENGINE"
"44","1577","24GRE","GREASE THE WHEELS"
I tried removing whitespaces by giving a command :1,$s/ //g This removes all the whitespace and renders the file as shown below which defeats the purpose. I want GREASE THE ENGINE with spaces.
44,1577,23GRE,GREASETHEENGINE
44,1577,23GRE,GREASETHEENGINE
44,1577,24GRE,GREASETHEWHEELS
Appreciate any or all help.
Thanks
You can use this substitute command in vi:
:1,$s/ *,/,/g
:1,$s/ *$//
:1,$s/,/","/g
First we replace trailing spaces then replace all spaces followed by , to a single ,. Finally we match each field that is not a comma and quote them.
[[:blank:]] will match a space or tab.
For your input it gives:
"44","1577","23GRE","GREASE THE ENGINE"
"44","1577","23GRE","GREASE THE ENGINE"
"44","1577","24GRE","GREASE THE WHEELS"
Another possibility:
%s/\s\+\([,$]\)/"\1"/g
%s/^/"/g
%s/$/"/g
Remove any sequence of white space characters (white space, tab, etc.) before a comma or the end of line;
Add " at the beginning of every line
Add " at the end of every line
If you had an empty line at the end of the file, you will end up with a line of "" which is easy to delete.

Regex in Excel VBA Special Characters and Embedded Spaces

I have to parse a huge file, but one of the values is causing me a lot of grief.
It is a fixed length field of six characters. The description of the allowable values is:
Left justified; space filled. Cannot contain special characters or embedded spaces. If data is unavailable, space filled.
What I have attempted so far is to check:
If Code = " " Then
MsgBox "Code is Space Filled."
This will check if it is all space filled, which is ok.
Next I check if there is any special characters using the following function:
With ObjRegex
.Global = True
.Pattern = "[^a-zA-Z0-9\s]+"
StripNonAlpha = .Replace(Replace(TextToReplace, "-", Chr(32)),
End With
I can compare two strings, the original code and the stripped of special characters one. If they don't match then it contains a special character and is not valid.
It is the spaces that are causing me issues. I have to check for left aligned (no leading spaces followed by characters) and no embedded spaces, trailing spaces are OK.
I have tried a few variations of the above function but to no avail.
e.g. (wrong):
(^\sa-zA-Z0-9\sa-zA-Z0-9)+
I would appreciate any pointer. If there is a more 'all in one' regex that makes more sense that would be great and if regex is the wrong way to go I'm more than happy happy to abandon them.
Partial answer:
Demo
Regex: (?=[a-zA-Z0-9\s]{6})[a-zA-Z0-9]*\s*
Drawbacks: It will match > 6 chars (but not less than 6)

How do I add a newline before each non-ascii word in Sublime-Text2?

I have a poorly formatted csv file of Korean words with English definitions. I'd like to add a new line before each Korean word. For example:
# I'd like to change this
하다,to do,크기,size,대기,on hold,
# Into this
하다,to do,
크기,size,
대기,on hold,
Using the regex ([^\x00-\x7F]*) I was able to highlight all instances of Korean words but when I try to replace them with \n$1 it works only for the first word after my last cursor position and then inserts a newline after each character.
Use + instead of *, (the former means 1 or more, the latter means 0 or more). Otherwise you get zero-width matches at every position:
[^\x00-\x7F]+

String replacement and strange characters

I have an HTML data in a char* and I would like to get it line by line, do some replacements and then add them all up together into a single string. This is the code that I use
std::string to, finalData;
finalData = "";
char* char_array = strtok(data, "\n");
while(char_array){
finalData += std::string(char_array);
char_array = strtok(NULL, "\n");
}
The problem is the data that I get at the end of this (finalData) has a lot of ^M characters and I am unable to search for it as it has a special character. Is there any way to completely eliminate the character?
I am guessing that it has something to do with conversion from c array to c++ string and to do with \n as tab is represented by ^I and cntrl is represented as ^
It seems that you are on a Windows system, or that the data originated on a Windows system. On a Windows system, newline is actually two characters: "\r\n". What you are seeing as ^M is the carriage-return character ('\r') of that newline sequence.
One way to remove those extra characters, would be to use std::string::find and std::string::erase in a loop.
Another way would be to manually copy, character by character, to a new std::string, except if the character is '\r'.

Removing whitespaces inside a string

I have a string lots\t of\nwhitespace\r\n which I have simplified but I still need to get rid of the other spaces in the string.
QString str = " lots\t of\nwhitespace\r\n ";
str = str.simplified();
I can do this erase_all(str, " "); in boost but I want to remain in qt.
str = str.simplified();
str.replace( " ", "" );
The first changes all of your whitespace characters to a single instance of ASCII 32, the second removes that.
Try this:
str.replace(" ","");
Option 1:
Simplify the white space, then remove it
Per the docs
[QString::simplified] Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space.
Once the string is simplified, the white spaces can easily be removed.
str.simplified().remove(' ')
Option 2:
Use a QRegExp to capture all types of white space in remove.
QRegExp space("\\s");
str.remove(space);
Notes
The OPs string has white space of different types (tab, carriage return, new line), all of which need to be removed. This is the tricky part.
QString::remove was introduced in Qt 5.6; prior to 5.6 removal can be achieved using QString::replace and replacing the white space with an empty string "".
You can omit the call to simplified() with a regex:
str.replace(QRegularExpression("\\s+"), QString());
I don't have measured which method is faster. I guess this regex would perform worse.