Resharper - How to add more linefeeds to the end of a surround template? - resharper

I am trying to do something quite simple. When resharper surrounds selected code with an if statement it does not all a new line at the end:
Original code:
var test = "Hello World";
var test2 = ("Goodbye");
Code wrapped:
if (true)
{
var test = "Hello World";
} var test2 = ("Goodbye");
I want it like this:
if (true)
{
var test = "Hello World";
}
var test2 = ("Goodbye");
I have edited the if surrpound template to have newlines at the end and have even restarted VS. No luck. Example:
How do I add a newline after the surround code?
Is there a list somewhere of the tags available for these templates? Perhaps it is a tag that I need?

Related

Issue concatenating two strings containing '&' in dart

I have a code like this :
// Language = Dart
var someVariable = 'Hello';
var someOtherVariable = 'World';
var str = 'somedomain?x=${someVariable}&y=${someOtherVariable}';
return str;
// Expected:
// somedomain?x=Hello&y=World;
// Actual
// somedomain?x=Hello
If I replace the & character with any alphabets, it is able to successfully concatenate. What am I doing wrong.
This is the actual code which I used in FlutterFlow, and am having issues with:
Future<String> getEventUrlFromReference(BuildContext context, DocumentReference? eventReference) async {
var userId = currentUser?.uid as String;
return "https://somedomain.com/event?eventReference=${eventReference?.id}" + "&invitedBy="+userId;
}
// result: https://somedomain.com/event?eventReference=referencevalue
This was a string encoding issue. I was using the result of my function/code as body text in sms://<number>?&body=<string_containigng_&_character>; The text which is appended to the sms text truncates at the & character, and I made a mistake assuming it's a string concatenation issue.

how can i get the code of the blocks connected to my custom block by blockly

everyone.
Hope you are doing well.
I have created my custom block using block factory.
The code for block definition is
Blockly.Blocks['web'] = {
init: function() {
this.appendDummyInput()
.appendField("When ")
.appendField(new Blockly.FieldDropdown([["button1","OPTIONNAME"]]), "NAME")
.appendField(".Click");
this.appendStatementInput("NAME")
.setCheck(null)
.appendField("do");
this.setColour(120);
this.setTooltip("Triggers when the button is clicked");
this.setHelpUrl("");
}
};
And the code for Generator stub:
Blockly.JavaScript['web'] = function(block) {
var dropdown_name = block.getFieldValue('NAME');
var statements_name = Blockly.JavaScript.statementToCode(block, 'NAME');
// TODO: Assemble JavaScript into code variable.
var code = '$(button).on("click", function(){})';
return code;
};
And the block is
How can i get the code of the blocks which are added to this button1 block.
please guide me i am new to blockly.
Regards,shiva
Doesn't your statements_name variable contain the data you need?
code = `var code = \$(${statements_name}).on("click", function(){});`
Note how I'm escaping your "$" to not interfere with the template string format.
(Sidenote: You also have to get the statements in the "do" statement input. You are using the same name for it: "NAME" which is going to be problematic)

Is there a way to replace several occurences in a HTML file in one line?

Please can you tell me how to make shorter this code. i wanna do it in one line.
var htmlstring = "{{1}}Hello {{2}}, clic here !";
var firststep = htmlstring.replace('{{1}}', "http://google.fr");
var secondstep = htmlstring.replace('{{1}}', "http://google.fr");
var thirdstep = secondstep.replacee('{{2}}', "Mister");
In short,
I have it:
{{1}}Hello {{2}}, clic here !
I wanna have this at the end:
http://google.frHello Mister, clic here !"
Sure, use String.replace and regexp:
const html = '{{1}}Hello {{2}}, click here !'
const url = 'http://google.fr';
const name = 'Mister';
const output = html.replace(/\{\{1\}\}/g, url).replace(/\{\{2\}\}/g, name);
I have no Idea how you can replace both {{1}} and {{2}} in one go, but you can replace both occurences of {{1}} by using this function:
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
Use it like this:
var htmlstring = '{{1}}Hello {{2}}, clic here !';
htmlstring.replaceAll("{{1}}", "http://google.fr");
htmlstring.replaceAll("{{2}}", "Mister");
ES6 Update:
You can now use an even better function for the replaceAll() method:
String.prototype.replaceAll = function(search, replacement) {
return this.split(search).join(replacement);
};
This will utilize .split() to first make an array without the search value and then .join() that Array with the replacement:
String.prototype.replaceAll = function(search, replacement) {return this.split(search).join(replacement);};
let htmlstring = `{{1}}Hello {{2}}, click here !`;
console.log(htmlstring.replaceAll("{{1}}","https://google.fr").replaceAll("{{2}}", "Mister"));

How can i replace a specific word in a string in swift?

I am looking for a way to replace a word inside a string in swift. Can anyone help?
this is what I have so far, I can find the specific word, but i do not know how to replace it...
var str = "helo, playgound"
var findWords = ["helo","playgound"]
var replaceWords = ["hello","playground"]
extension String {
var wordList:[String] {
return "".join(componentsSeparatedByCharactersInSet(NSCharacterSet.punctuationCharacterSet())).componentsSeparatedByString(" ")
}
}
func stringToArray() -> Array<String> {
var arr = str.wordList
return arr
}
func correction(var _arr:Array<String>) -> String{
for var i = 0; i < _arr.count; i++ {
if str.lowercaseString.rangeOfString(findWords[i]) != nil {
println("exists")
}
}
return str
}
It depends what your definition of a "word" is. If you're looking for an intelligent built-in notion of a "word", the easiest solution is probably to use NSRegularExpression, which knows where "word" boundaries are:
var s = NSMutableString(string:"hello world, go to hell")
let r = NSRegularExpression(
pattern: "\\bhell\\b",
options: .CaseInsensitive, error: nil)!
r.replaceMatchesInString(
s, options: nil, range: NSMakeRange(0,s.length),
withTemplate: "heaven")
After that, s is "hello world, go to heaven", which is the right answer; we replaced the "hell" that is a word, but not the "hell" in "hello". Notice that we are also matching case-insensitively, which seems to be one of your desiderata.
That example shows how do just one pair ("hell" and "heaven") but it is easy to abstract it into a method so that you can do it again and again for further pairs:
var str = "helo, playgound"
var findWords = ["helo", "playgound"]
var replaceWords = ["hello", "playground"]
func correct(str:String, orig:String, repl:String) -> String {
var s = NSMutableString(string:str)
let r = NSRegularExpression(
pattern: "\\b\(orig)\\b",
options: .CaseInsensitive, error: nil)!
r.replaceMatchesInString(
s, options: nil, range: NSMakeRange(0,s.length),
withTemplate: repl)
return s
}
for pair in Zip2(findWords,replaceWords) {
str = correct(str, pair.0, pair.1)
}
str // hello, playground
The easiest is probably this:
let statement = "Swift is hard."
let swiftRange = statement.startIndex..<advance(statement.startIndex, 5)
let newStatement = statement.stringByReplacingCharactersInRange(swiftRange, withString: "Objective-C")
// now newStatement = "Objective-C is hard."
Following a longer commenting tour: The above is under the assumption of the OP "I can find the specific word, but i do not know how to replace it...", so it's not about finding a "word" which to define is another discussion. It's just about replacing an already found word.
Another word on stringByReplacingCharactersInRange: #matt states that this is Cocoa cross-over. In that case Apple is telling a plain lie:
I fostered the web but there's no Apple source telling anything. Only the Foundation method for NSString. Their Swift book is silent too (in many respects). Well, I don't trust Apple anyway any longer since Yosemite-fail.

Flex embedded string resource encoding

I embed a text file into my Flex project and read its contents using code like this:
[Embed(source = "../../data/abc.txt", mimeType = "application/octet-stream")]
private var r_Abc:Class;
...
var xx:ByteArray = new r_Abc();
var abc:String = xx.toString();
The contents of the file is abc. The problem is that the string loaded from the file is not comparable to other strings even though when printed or viewed in the debugger (in FlashDevelop) it seems to be perfectly fine.
trace(abc); // abc
trace("abc" == abc); // false
How do I convert it into a proper string? I tried to use the string methods such as substring to create a copy, but that does not seem to be the solution.
Here's my sample:
<?xml version="1.0" encoding="utf-8"?>
<s:Application minWidth="955" minHeight="600"
creationComplete="creationCompleteHandler(event)"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.core.ByteArrayAsset;
import mx.events.FlexEvent;
// my file is "ABC "
// strangely enough if I remove the space at the end the string in code is empty
[Embed(source="data/abc.txt", mimeType="application/octet-stream")]
private var abcFile:Class;
protected function creationCompleteHandler(event:FlexEvent):void
{
var abcByteArray:ByteArrayAsset = ByteArrayAsset(new abcFile());
var abc:String = abcByteArray.readUTFBytes(abcByteArray.length);
trace(abc); // ABC (has a space at the end)
trace(abc == "ABC "); // true, but notice the space at the end
}
]]>
</fx:Script>
</s:Application>
My suggestion is to check for trailing spaces, new lines. Also try to place some sort of an EOF character at the end of the file.

Resources