How do I escape a comma when using a markup extension? - wpf

The value of the second parameter of the markup extension I am using is a string containing some commas and I don't want those commas to be interpreted as parameter separators by the xaml interpreter / parser, but that the whole string as such including the commas is used as value.
Here is an example:
<SomeControl SomeProperty="{Wpf:MyExtension MyFirstParameter,
MySecondParameter, being a string, containing some commas.}" />
Google didn't help, I found some similar issues but none apply to this problem:
http://msdn.microsoft.com/de-de/library/ms744986.aspx
http://msdn.microsoft.com/en-us/library/ms748250.aspx

You can use single quotes to encapsulate a string; so your mark-up should look something like:
<SomeControl SomeProperty="{Wpf:MyExtension MyFirstParameter,
'MySecondParameter, being a string, containing some commas.'}" />
I'm not sure whether you will also need the {} escape sequence mark-up.

Related

React-csv not allowing me to change or remove enclosing characters

I am trying to export a csv using react-csv. The documentation says that I should be able to modify the enclosing character with an enclosingCharacter prop, but it doesn't seem to make a difference when I set it. It always uses a quotation mark as the enclosing character. I've tried single quotes, false, null. Nothing works. Ideally, I'd like for there to be no enclosing characters and just use commas for the delimiter. What am I doing wrong?
<CSVLink
data={this.state.csvData}
filename="sample.csv"
enclosingCharacter={`'`}
/>
Current output looks like this: "data1","data2","data3"
Desired output should look like this: data1,data2,data3

regex with OR condition not working in angularjs [duplicate]

I'm creating a javascript regex to match queries in a search engine string. I am having a problem with alternation. I have the following regex:
.*baidu.com.*[/?].*wd{1}=
I want to be able to match strings that have the string 'word' or 'qw' in addition to 'wd', but everything I try is unsuccessful. I thought I would be able to do something like the following:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
but it does not seem to work.
replace [wd|word|qw] with (wd|word|qw) or (?:wd|word|qw).
[] denotes character sets, () denotes logical groupings.
Your expression:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
does need a few changes, including [wd|word|qw] to (wd|word|qw) and getting rid of the redundant {1}, like so:
.*baidu.com.*[/?].*(wd|word|qw)=
But you also need to understand that the first part of your expression (.*baidu.com.*[/?].*) will match baidu.com hello what spelling/handle????????? or hbaidu-com/ or even something like lkas----jhdf lkja$##!3hdsfbaidugcomlaksjhdf.[($?lakshf, because the dot (.) matches any character except newlines... to match a literal dot, you have to escape it with a backslash (like \.)
There are several approaches you could take to match things in a URL, but we could help you more if you tell us what you are trying to do or accomplish - perhaps regex is not the best solution or (EDIT) only part of the best solution?

What's the purpose of single quotes in WPF Bindings?

In analogy to this question, I am curious how to interpret the expression {Binding ''} in WPF.
Note that there are two apostrophes after Binding.
In addition to a Google search I looked at this link provided in the linked question above, but was not able to assert the meaning of the two apostrophes after Binding.
What I came across were String Format expressions, where the apostrophe is used inside double quotes to denote another String expression. But I doubt this is the case here, for this question.
What does this expression mean?
It's equivalent to an empty Path. The apostrophes simply enclose whatever you write between them. So in your case it's a Binding to the DataSource (without a Path) - although I have to say, I've never seen it used that way.
The reason you probably didn't find this in any Bindings related context is because it's actually a feature that is available to all XAML markup extensions (like Binding, Static, StaticResource, etc.).
MSDN: Details about how markup extensions are parsed
The text value of either a MEMBERNAME or STRING is read as follows. Leading whitespace characters are consumed without being represented in the generated token. If the first non-whitespace character is a quote (either Unicode code point 0022, Quotation Mark, or 0027, Apostrophe), the tokenizer proceeds as follows:
The first quote is consumed and is not represented in the token’s value.
The text value becomes the characters up to but not including the next matching quote (i.e. a character of the same code point as the opening quote) that is not preceded by a “\” character. All these characters and also the closing quote are consumed. Any “\” characters in the resulting text value are removed.
Whitespace characters following the closing quote are consumed, and are not represented in the token.
Take this simple (and rather useless) extension for example:
public class StringExtension : MarkupExtension
{
public StringExtension()
{ }
public StringExtension(string value)
{
Value = value;
}
public string Value { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider)
{
return Value;
}
}
The extension could be used like this (all identical results):
<!-- via constructor (1 argument) -->
<TextBlock Text="{local:String text}"/>
<!-- via constructor (1 argument) -->
<TextBlock Text="{local:String 'text'}"/>
<!-- via empty constructor + named property -->
<TextBlock Text="{local:String Value=text}"/>
<!-- via empty constructor + named property -->
<TextBlock Text="{local:String Value='text'}"/>
So, what are the 's used for? Well for example for leading and trailing Whitespaces.
<!-- no whitespaces -->
<TextBlock Text="{local:String text }"/>
<!-- whitespaces -->
<TextBlock Text="{local:String ' text '}"/>

Pass regex to variable (angular)

I have such a code ng-init="validationRegex = '#RegularExpression.expression'" where RegularExpression.expression is c# string variable = "(\w+\/|\w+\\)+(\w+)\.\w+". I want to pass variable value to angular controller using ng-init. But in the end I get (w+/|w+\)+(w+).w+. How can I get right value?
I assume that your C# code is actually: #"(\w+\/|\w+\\)+(\w+)\.\w+". The # avoids needing the evil escaped escape.
You will likely need to use the evil escaped escape in this case. Note that you don't need to escape the / if you are putting it directly in a string (if you are using it how I think you are). You can also use braces to minimize the escaping. So you can take this regex:
(\w+/|\w+\\)+(\w+)[.]\w+
and pass it through regex planet to get this:
"(\\w+/|\\w+\\\\)+(\\w+)[.]\\w+"
I would not recommend manual conversion since you already have an escaped backslash.
Double escape the string using:
#RegularExpression.expression.Replace(#"\", #"\\")
When it comes through on the JavaScript side it will be singly-escaped again.

Sublime Text Snippet: Create camelcased string from the hyphenated file name

I am trying to create a Sublime Text snippet for AngularJs. This snippet should expand to AngularJs controller (or service, etc or any ng component). In the resulting code, it should construct the controller name in camelCase from the hyphenated file name.
For example:
when I type the snippets strings, say, ngctrl in an empty file called employee-benefits-controller.js, it should expand as given below:
angular.module('').controller('EmployeeBenefitsController', ['', function(){
}]);
I am trying to use the $TM_FILENAME variable by applying a regex on it to achieve this conversion. If anyone has already done this, please let us know.
You could use something like this:
<snippet>
<content><![CDATA[
angular.module('${1:moduleName}').controller('${TM_FILENAME/(^|-|\.js)(.?)|/\U\2\E/g}', ['', function(){
${2://functionCode}
}]);
]]></content>
<tabTrigger>ngctrl</tabTrigger>
</snippet>
Notes:
Note 1: maybe you want to change the scope so that the snippet its only triggered in javascript context.
Note 2: I'm not familiar with angularjs, so I don't know its naming conventions (I have supposed that an uppercase letter its needed after a hyphen [-] character and at the begining of the name, but I don't know if a uppercase character its needed after a dot character for example). So, you'll probablly have to adapt the snippet.
Note 3: expression explained:
${TM_FILENAME/(^|-|.js)(.?)/\U\2\E/g}
TM_FILENAME its the var_name item
(^|-|.js)(.?) its the regex (the parts of the variable we select).
\U\2\E its the format_string (how we format what we have selected).
g its the options (g means globally, so every time something its selected the format its given).
TM_FILENAME: the file name with the extension included.
\U => init uppercase conversion. \E => finish uppercase conversion. \2 => second group, i.e. second parénthesis, (.?), its a single char or an empty string.
(^|-|.js)(.?) First we look for the beginning of the word (^), or for a hypen character (-), or for the extension (.js).
(.?) Then we select in a parenthesis group (second group) the character (if any) after that hypen (or at the beginning of the word or after the extension).
Finally we use the uppercase conversion over that selected character as explained. Note that as there is not character after the extension, we are simply removing the extension from the output.
Note 4: as you probablly know, using ${1:moduleName} and ${2://functionCode} allows you to quickly move (using tab) and edit the important parts of the snippet once it has been triggered, such as the module or the function code.

Resources