I am currently working on an app that connects to custom server using NSStream. Once connected the app allows for user input via a textfield. In order for the server to recognize an incoming command a \t needs to be first and then the string from something like self.inputField.text.
I have everything working up to this point as far as opening/closing of sockets, sending/receiving etc.
The problem is my sent string looks like so: \tSOMECOMMAND but the \t is not being interpreted as a tab but as string '\tSOMECOMMAND'. How can I prepend a \t (tab) to the text in my input field?
As always thanks in advance!
You shouldn't require the user to add the tab character as it's counter-intuitive, easy to forget and an implementation detail they don't need to know about.
In your controller object:
Get the string from the text field.
Prepend the tab character.
Send the string to the server.
A user typing a backslash and a 't' is not necessarily the same as an escape sequence for a tab.
Those will be sent as two literal characters.
Your code needs to identify that escape sequence string and replace the string with a tab character. That's what the compiler does to an escape sequence when it is found within delimiters within which it expects there might be an escape sequence.
Related
I have using Variables refresh text from MSSQL, but the return garbled characters that contains Chinese characters.
Running the same script in MSSQL returns the correct result without garbled.
Do you have the same issues , and how to fix it ?
Can you share sql refresh variable?
I think you should remove special character when you select to refresh variable?
Something like this(on Oracle):
select
REGEXP_REPLACE('漢字123 vietnamdataengineer#gmail.com 漢字','[^a-z_A-Z0-9 ]') as STR
from dual;
I have a encrypted string which would be passed from the server side, now I want to test to convert it into readable language by some conventional decoding method.
but I found I totally cannot use the string:
The error shows: invalid escape sequence in literal.
There exists some conversions in swift string like "\(variable)" or "\b".
Is there a way for me to use pure String?
For example. in python, I can declare a = """content""" to represent pure String
It's the backslash (\), just before the character the up-arrow is pointing to in the error message. In a literal, this needs to be represented by a double backslash (\\).
This issue won't arise once you're no longer testing and you're doing this all with actual values; it's a feature only of literal strings.
I recently fount a quick solution:
Use ' content ' instead of " content ", then Xcode would give you a warning.
Press Fix-it, Xcode would automatically add \ at right places to avoid literal convention.
I would suggest you save the string in a file in you app and read it from there, to avoid having to modify the string (it's a rather ugly string and you will have to escape a bunch of stuff).
You can use NSBundle.pathForResource and NSString.initWithContentsOfFile to get the string into memory from the file.
I'm using selected/highlighted text by the user to generate the intent/tweet?text= content for the Twitter widget's "Tweet text" function.
It works great except when it encounters either opening or closing double/single curly quotes within the element's content: ‘ ’ “ ” (‘ ’ “ ”). When any of those characters is included in the selected text, the entire Tweet text dialog window is blank.
I've tried various javascript methods to search/replace the ASCII codes or the Unicode versions of those but to no avail.
The escape(text) method is already being used before the text gets to the Twitter widget, so I'm confused as to why it's choking. In the location bar it shows that these characters are being converted to their Unicode versions like u201C.
What could be causing the Tweet text box to fail on these characters even though it seems to be properly converting them anyway?
I discovered that one needs to search/replace the literal entities themselves, not ASCII codes nor their Unicode counterparts.
So the solution for using selected text in a Twitter widget text intent is:
text = text.replace(/“/g, "\'").replace(/”/g, "\'").replace(/‘/g, "\'").replace(/’/g, "\'");
The entities don't need to be escaped.
I'm currently modifying my regex for this:
Extracting email addresses in an html block in ruby/rails
basically, im making another obfuscator that uses ROT13 by parsing a block of text for all links that contain a mailto referrer(using hpricot). One use case this doesn't catch is that if the user just typed in an email address(without turning it into a link via tinymce)
So here's the basic flow of my method:
1. parse a block of text for all tags with href="mailto:..."
2. replace each tag with a javascript function that changes this into ROT13 (using this script: http://unixmonkey.net/?p=20)
3. once all links are obfuscated, pass the resulting block of text into another function that parses for all emails(this one has an email regex that reverses the email address and then adds a span to that email - to reverse it back)
step 3 is supposed to clean the block of text for remaining emails that AREN'T in a href tags(meaning it wasn't parsed by hpricot). Problem with this is that the emails that were converted to ROT13 are still found by my regex. What i want to catch are just emails that WEREN'T CONVERTED to ROT13.
How do i do this? well all emails the WERE CONVERTED have a trailing "'.replace" in them. meaning, i need to get all emails WITHOUT that string. so far i have this regex:
/\b([A-Z0-9._%+-]+#[A-Z0-9.-]+.[A-Z]{2,4}('.replace))\b/i
but this gets all the emails with the trailing '.replace i want to get the opposite and I'm currently stumped with this. any help from regex gurus out there?
MORE INFO:
Here's the regex + the block of text im parsing:
http://www.rubular.com/r/NqXIHrNqjI
as you can see, the first two 'email addresses' are already obfuscated using ROT13. I need a regex that gets the emails ohhellzyeah#ribute.com and kaboom#yahoo.com
On negative lookaheads
You can use a negative lookahead to assert that a pattern doesn't match.
For example, the following regex matches all strings that doesn't end with ".replace" string:
^(?!.*\.replace$).*$
As another example, this regex matches all a*b*, except aabb:
^(?!aabb$)a*b*$
Ideally,
See also
regular-expressions.info/Lookaheads and anchors
Flavor comparison - unfortunately, Ruby doesn't support lookbehinds
Specific solution
The following regex works in this scenario: (see on rubular.com):
/\b([A-Z0-9._%+-]+#(?![A-Z0-9.-]*'\.replace\b)[A-Z0-9.-]+\.[A-Z]{2,4})\b/i
In my asp.net mvc page I create a link that renders as followed:
http://localhost:3035/Formula/OverView?colorId=349405&paintCode=744&name=BRILLANT%20SILVER&formulaId=570230
According to the W3C validator, this is not correct and it errors after the first ampersand. It complains about the & not being encoded and the entity &p not recognised etc.
AFAIK the & shouldn't be encoded because it is a separator for the key value pair.
For those who care: I send these pars as querystring and not as "/" seperated values because there is no decent way of passing on optional parameters that I know of.
To put all the bits together:
an anchor (<a>) tag's href attribute needs an encoded value
& encodes to &
to encode an '&' when it is part of your parameter's value, use %26
Wouldn't encoding the ampersand into & make it part of my parameter's value?
I need it to seperate the second variable from the first
Indeed, by encoding my href value, I do get rid of the errors. What I'm wondering now however is what to do if for example my colorId would be "123&456", where the ampersand is part of the value.
Since the separator has to be encoded, what to do with encoded ampersands. Do they need to be encoded twice so to speak?
So to get the url:
www.mySite.com/search?query=123&456&page=1
What should my href value be?
Also, I think I'm about the first person in the world to care about this.. go check the www and count the pages that get their query string validated in the W3C validator..
Entities which are part of the attributes should be encoded, generally. Thus you need & instead of just &
It works even if it doesn't validate because most browsers are very, very, very lenient in what to accept.
In addition, if you are outputting XHTML you have to encode every entity everywhere, not just inside the attributes.
All HTML attributes need to use character entities. You only don't need to change & into & within script blocks.
Whatever
Anywhere in an HTML document that you want an & to display directly next to something other than whitespace, you need to use the character entity &. If it is part of an attribute, the & will work as though it was an &. If the document is XHTML, you need to use character entities everywhere, even if you don't have something immediately next to the &. You can also use other character entities as part of attributes to treat them as though they were the actual characters.
If you want to use an ampersand as part of a URL in a way other than as a separator for parameters, you should use %26.
As an example...
Hello
Would send the user to http://localhost/Hello, with name=Bob and text=you & me "forever".
This is a slightly confusing concept to some people, I've found. When you put & in a HTML page, such as in <a href="abc?def=5&ghi=10">, the URL is actually abc?def=5&ghi=10. The HTML parser converts the entity to an ampersand.
Think of exactly the same as how you need to escape quotes in a string:
// though you define your string like this:
myString = "this is \"something\" you know?"
// the string is ACTUALLY: this is "something" you know?
// when you look at the HTML, you see:
<a href="foo?bar=1&baz=2">
// but the url is ACTUALLY: foo?bar=1&bar=2