How to do a mixed input NSTokenField - nstokenfield

I'm trying to get an NSTokenField working that allows editing to a similar post here.
The answer that was provided gave me the key but something is still off. What should the token character set be set as? My tags will be in this format "< token text >". Setting the character tokenizer to " " results in the " " between words being removed.
What should I be using as the token character set? This is driving me crazy!

I haven't tried this, but I would use " " as the tokenizer and then add a space at the end of your display string which is not in your editing string.
So -tokenField:displayStringForRepresentedObject: would return "Hello " and -tokenField:editingStringForRepresentedObject: would return "Hello".
The alternative would be using "<" and ">" as the tokenizing characters, but I could see a lot of potential issues arising from that.

Related

what is the equivalent of "\n" in vb.net

This may seem simple.
It could be vbNewLine
or it can be
https://learn.microsoft.com/en-us/dotnet/api/system.environment.newline?redirectedfrom=MSDN&view=net-6.0#System_Environment_NewLine
However, that is NOT equivalent with "\n"
That is equivalent with
\r\n for non-Unix platforms, or \n for Unix platforms.
What about if I want \n no matter what. \
I tried to search for similar questions and I can't even find it.
There is nothing here either.
https://learn.microsoft.com/en-us/dotnet/api/system.environment.newline?redirectedfrom=MSDN&view=net-6.0#System_Environment_NewLine
So not easy to fine.
Update:
One answer says that "\n" means vbNewLine both in windows and in Linux.
Well, I am writing a vb.net windows program that interact with linux machine. You know, usual API stuff. In which case I need a character in windows that always mean "\n" in linux.
Basically, I need the chr(10) character. Not chr(10)+chr(13) character.
I think the answer I wrote my self is the answer to that.
And I do not think there is a simple answer on that.
Differences Between vbLf, vbCrLf & vbCr Constants may make things clear. However, people that find that question are people that already guess that vbLf may be a solution.
In fact, the questions and the answers over there do not even link "\n" to vbLF at all. They just say that vbLF is line feed. Is it "\n"? Another technicality
This question answer the question more directly. So what's equivalent to linux/unix "\n" no matter what is vbLf
using Microsoft.VisualBasic.CompilerServices;
namespace Microsoft.VisualBasic
{
// Summary:
// Represents a linefeed character for print and display functions.
[__DynamicallyInvokable]
public const string vbLf = "\n";
}
So the answer is
Microsoft.VisualBasic.vbLf
Somehow I can just use vbLf because Microsoft.VisualBasic is so often used it's in my project list I guess.
Update:
One answer says that "\n" means vbNewLine both in windows and in Linux.
Well, I am writing a vb.net windows program that interact with linux machine. You know, usual API stuff. In which case I need a character in windows that always mean "\n" in linux.
Basically, I need the chr(10) character. Not chr(10)+chr(13) character.
I think vbLf is the right answer.
And I do not think there is a simple answer on that.
Differences Between vbLf, vbCrLf & vbCr Constants may make things clear. However, people that find that question are people that already guess that vbLf may be a solution.
This question answer the question more directly. So what's equivalent to linux/unix "\n", which is the line feed chr(10) character no matter what is vbLf
For VB.Net, which tends to run on Windows, the closest map to \n is vbCrLf. This is different than just vbLf, because vbLf always maps directly to the ascii line feed character (10), but \n on some platforms will map to whatever the local system uses for line endings, rather than a simple line feed. On Windows, this is typically the 13/10 vbCrLf pair.
The easiest way to include these in code strings is via the new-ish interpolated strings:
$"This string{vbCrLf}includes some{vbCrLf}line breaks."
If you want to go platform-agnostic, the closest match is Environment.NewLine. And since that's a mouthful to use over and over you can always assing the value to a variable with a shorter name, like this:
Dim vbNl As String = Environment.NewLine
You ought to be using the ControlChars class in VB.NET. ControlChars.Lf is a line feed, i.e. equivalent to "\n", while ControlChars.Cr is a carriage return, i.e. equivalent to "\r". ControlChars.CrLf and ControlChars.NewLine are both equivalent to "\r\n". Environment.NewLine will give you "\r\n", "\n" or "\r", depending on the platform.

string is partially parsed when symbol "&" is present

If I have a string like "Fuel & Additives" when my XML parser goes through it ignores anything BEFORE the "&" symbol, why?
if ([elementname isEqualToString:#"GLDesc"])
{
currentParsedObjectContainer.GLDesc = currentNodeContent;
NSLog(#"%#",currentParsedObjectContainer.GLDesc);
}
The ampersand character (&) and the
left angle bracket (<) may appear in
their literal form only when used as
markup delimiters, or within a
comment, a processing instruction, or
a CDATA section. If they are needed
elsewhere, they must be escaped using
either numeric character references or
the strings "&" and "<"
respectively.
http://www.w3.org/TR/2000/REC-xml-20001006#syntax
As the above snippet states, you'll need to escape & to the string & before passing it to the XML parser.
I'm going to say it has something to do with character codes (for example &lt). I'm not really familiar with xml though, so I'm not sure. Try &amp?

Trying to parse non well-formed XML using NSXMLParser

I am parsing XML Data using NSXMLParser and I notice now, that the Elements can contain ALL characters, including for example a &. Since the parser is giving an error when it comes across this character I replaced every Occurence of this character.
Now I want to make sure to handle every of these characters that may cause Errors.
What are they and how do you think I should handle these characters best?
Thanks in advance!
To answer half your question, XML has 5 special characters that you may want to escape:
< -- replace with <
> -- replace with >
& -- replace with &
' -- replace with &apos;
and
" -- replace with "
Now, for the other half--how to find and replace these without also replacing all the tags, etc... Not easy, but I'd look in to regular expressions and NSRegularExpression: http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSRegularExpression_Class/Reference/Reference.html
Remember, depending on your use case, to escape the values of the parameters on tags, too; <tag parameter="with "quotes"" />
You should encode these characters for instance & becomes & or " becomes "
When it goes through the parser it should come out ok. Your other option is to use a different XML parser like TBXML which doesn't do format checking.

Comma, ')',or valid expression continuation expected

I need my VB.net to write a file containing the following line
objWriter.WriteLine ("TEXTA " (FILEA) " TEXTB")
Unfortunatly the variable (FILEA) is causing problems i now get the error
Comma, ')', or valid expression continuation expected.
Could someone explain this please?
You're not concatenating (joining) the strings proerly...
objWriter.WriteLine ("TEXTA " & FILEA & " TEXTB")
A better style to get into the habit of using is:
objWriter.WriteLine (string.format("TEXTA {0} TEXTB", FILEA))
The FILEA variable replaces the {0} placeholder in the format string. Depending on what the writer you're using is, you may have a formatted overload so you could just do:
objWriter.WriteLine ("TEXTA {0} TEXTB", FILEA)
And since you asked for an explanation;
The compiler is asking you what exactly you want it to do - you've given it 3 variables (String, variable, String) and haven't told it that you want to join them together - It's saying that after the first string "TEXTA", there should either be the closing bracket (to end the method call), a comma (to pass another parameter to the method) OR a "valid continuation expression" - ie something that tells it what to do with the next bit. in this case, you want a continuation expression, specifically an ampersand to signify "concatenate with the next 'thing'".
Presumably you're looking for string concatenation? Try this:
objWriter.WriteLine("TEXTA" & FILEA & "TEXTB");
Note that FILEA isn't exactly a conventional variable name... which leads me to suspect there may be something else you're trying to achieve. Could you give more details?

why does using "\" shows error in jython

I am trying to use a copy command for Windows and we have directories such as c:\oracle.
While trying to execute one such, we get the following error:
source_file=folder+"\"
^
SyntaxError: Lexical error at line 17, column 23. Encountered: "\r" (13), after : ""
Here folder is my path of c:\oracle and while trying to add file to it like:
source=folder+"\"+src_file
I am not able to do so. Any suggestion on how to solve this issue?
I tried with / but my copy windows calling source in os.command is getting "the syntax is incorrect" and the only way to solve it is to use \ but I am getting the above error in doing so.
Please suggest. Thanks for your help
Thanks.
Short answer:
You need:
source_file = folder + "\\" + src_file
Long answer:
The problem with
source_file = folder + "\" + src_file
is that \ is the escape character. What it's doing in this particular case is escaping the " so that it's treated as a character of the string rather than the string terminator, similar to:
source_file = folder + "X + src_file
which would have the same problem.
In other words, you're trying to construct a string consisting of ", some other text and the end of line (\r, the carriage return character). That's where your error is coming from:
Encountered: "\r" (13)
Paxdiablo is absolutely correct about why \ isn't working for you. However, you could also solve your problem by using os.path.normpath instead of trying to construct the proper platform-specific path characters yourself.
In all programming languages I know of, you can't put a quote inside a string like this: "this is a quote: "." The reason for this is that the first quote opens the string, the second then closes it (!), and then the third one opens another string - with the following two problems:
whatever is between the quotes #2 and #3 is probably not valid code;
the quote #3 is probably not being closed.
There are two common mechanisms of solving this: doubling and escaping. Escaping is far more common, and what it means is you put a special character (usually \) in front of characters that you don't want to be interpreted in their usual value. Thus, "no, *this* is a quote: \"." is a proper string, where the quote #2 is not closing the string - and the character \ does not appear.
However, now you have another problem - how do you actually make the escape character appear in a string? Simple: escape it! "This is an escape: \\!" is how you do it: the backslash #1 is the escape character, and the backslash #2 is the escapee: it will not be interpreted with its usual escape semantics, but as a simple backslash character.
Thus, your line should say this:
source=folder+"\\"+src_file
BTW: upvote for both #paxdiablo (who got in before my diatribe) and #Nick (who has a proper Pythonic way to do what you want to do)