Embedding text in AS2, like HEREDOC or CDATA - string

I'm loading a text file into a string variable using LoadVars(). For the final version of the code I want to be able to put that text as part of the actionscript code and assign it to the string, instead of loading it from an external file.
Something along the lines of HEREDOC syntax in PHP, or CDATA in AS3 ( http://dougmccune.com/blog/2007/05/15/multi-line-strings-in-actionscript-3/ )
Quick and dirty solutions I've found is to put the text into a text object in a movieclip and then get the value, but I dont like it
Btw: the text is multiline, and can include single quotes and double quotes.
Thanks!

I think in AS2 the only way seems to do it dirty. In AS3 you can embed resources with the Embed tag, but as far as I know not in AS2.
If it's a final version and it means you don't want to edit the text anymore, you could escape the characters and use \n as a line break.
var str = "\'one\' \"two\"\nthree";
trace(str);
outputs:
'one' "two"
three
Now just copy the text into your favourite text editor and change every ' and " to \' and \", also the line breaks to \n.

Cristian, anemgyenge's solution works when you realize it's a single line. It can be selected and replaced in a simple operation.
Don't edit the doc in the code editor. Edit the doc in a doc editor and create a process that converts it to a long string (say running it through a quick PHP script). Take the converted string and paste it in over the old string. Repeat as necessary.
It's way less than ideal from a long-term management perspective, especially if code maintenance gets handed off without you handing off the parser, but it gets around some of your maintenance issues.

Use a new pair of quotes on each line and add a space as the word delimiter:
var foo = "Example of string " +
"spanning multiple lines " +
"using heredoc syntax."
There is a project which may help that adds partial E4X support to ActionScript 2:
as24x
As well as a project which adds E4X support to Haxe, which can compile to a JavaScript target:
E4X Macro for Haxe

Related

Is there a quick way to delete everything between certain tags, e.g. <head> and </head>, throughout the whole project (multiple pages) in VS Code?

I am trying to find a way to remove all from a tag pair in VS Code.
I’ve been using Notepad++ for this purpose, but for some unknown reason it doesn't work all the time. So, I hope if there is such a possibility in VS Code, it’d be more reliable.
Here is the instruction for Notepad++:
Search for -
<wp:post_name>[^<>]+</wp:post_name>
and replace all with -
<wp:post_name></wp:post_name>
Is there anything like this in VS Code?
I’d really appreciate it if someone can help.
Before using what is suggested in this solution, backup your files, and run the search and replace on a small sample. Be sure to check the outcome to all the possible combinations you can have in your files.
You can achieve what you need with Notepad++ (and SublimeText 3, with RegEx search and replace), and this answer will cover that. Since I've never used Visual Studio Code, I can't say if it will work in it as well.
Consider the following regular expression.
<foo>(.*?)<\/foo>
If we were to apply it to the following text:
<foo><some special chars>!##$%^&*</foo> sure, why not
<foo>Lorem</foo>
<foo>ipsum</foo>
<foo>sit</foo>
<foo>dolor</foo>
<foo>amet</foo>
<bar>elm stuff</bar>
more stuff for you <foo> something </foo> and even more stuff <foo>yes</foo>
it would match all the parts of the text which begin with <foo> and end with </foo>, regardless of what's between them.
If you want to play around with this, I've created an example here.
As far as using this in Notepad++, open the search window, navigate to the Find in files tab, and set it up like in the following image.
You would, of course, need to change the search and replacement strings to those you plan on using, optionally set up a file extension for which to do the replacement (Filters), and set the directory in which to perform find-and-replace.
Limitations
1. Nesting
In case your text contains nested tags of the same kind, like this:
Let's deal with nesting: <foo> some text <foo> a child foo!</foo> let's close the parent</foo>
doing the suggested RegEx search and replace, will turn the previous line of text into this:
Let's deal with nesting: <foo></foo> let's close the parent</foo>
If you don't have nested tags of the same kind, you should be in the clear. Unless...
2. Newlines
The provided RegEx will not match cases where your opening tag shows up in one line, and the closing tag shows up in another line. To match those, you would need to change the original RegEx:
<foo>(.*?)<\/foo>
to this:
<foo>([\s\S]*?)<\/foo>
\s will match any whitespace character (including newlines), while \S will match any non-whitespace character.

Add the ability to use tabulation in Nim

Yes, we can convert tabs to spaces via Sublime, VS-Code and etc, it's not a big problem.
But what if I want to get rid off this additional action ?
Found answer by adding this line to .nim file :
#? replace(sub = "\t", by = " ")
My additional question is :
What is this #?, how this thing works and what kind of variations I can find also, for example:
#!
#some_chinese_character
It is called a "source code filter", it's like a Nim preprocessor less powerful than macros and templates. You can read about it here: https://nim-lang.org/docs/filters.html
Anyway, I wouldn't recommend using it, but rather using an editor which replaces tabs with spaces, such as vscode. This seems more like an hack than an actual solution.

Sublime Text 3 AutoWrap breaks double quotes

I installed a package called Sublime Wrap Plus to insert line break after wrapping text at 80 characters.
However, this breaks for example, the "long long long quotes" into
"long long long...
long quotes"
Which is a syntax error. Anyone knows how to fix this?
The README is clear about this plugin detecting where to wrap paragraph text, not source code. Based on their epilogue, you should open up an Issue for additional features.
Code wise, if you do want to add additional logic to the mix, its written in Python and uses if statements like this one to parse the selected area as you see fit.

How to split comma-separated words?

How can i split my words in new line (i have a lot of them) currently separated with comma,
Example of my file contains words in a single line:
Viktor, Vajt, Adios, Test, Line, Word1, Word2, etc...
The the output file should look like:
Viktor
Vajt
Adios
Test
...
If you are using NotePad++, this can easily be done. See image below
If you – for some reason – want to stick with the doc Format (to keep formatting, etc.) you could use LibreOffice (http://de.libreoffice.org/) to do the following replacement:
I agree installing LibreOffice just for this replacement would be overkill though.
Not sure what language you are in but you could use an explode/split function which would create an array of values split at ','. Then you could loop through the array and append the new line special character "\n". You would wind up with something like:
$fileContentsAsString; //read file into string variable
$valuesArray = explode(',' $fileContentsAsString);
$outputString;
foreach($valuesArray as $item){
$outputString .= $item . "\n";
}
For a quick text edititng i'm using online tool (http://regexptool.org/). Also you can do it step by step (screen).

Using multiple delimiters with scanner - Java

I'm trying to use both tabs and newlines as delimiters to read from a .txt file. What I have at the moment is:
Scanner fileScanner = new Scanner(new FileReader("propertys.txt"));
fileScanner.useDelimiter("[\\t\\n]");
I've tried:
fileScanner.useDelimiter("\\t|\\n");
and
fileScanner.useDelimiter("[\\t|\\n]");
I've got no idea what's going wrong, I've searched around a lot and it looks like one of those should be working. Clearly I'm doing something wrong.
fileScanner.useDelimiter("\t|\n");
should work.
If you have two slashes "\n" the first acts as an escape and it won't work right.
For the regular expression used as a parameter in useDelimiter method, you should use newline as \n instead of \\n and tab as \t instead of \\t. From Java Pattern class: http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html.
A part from that, I think you should define you regular expression like, for example, this:
fileScanner.useDelimiter("\\s*[\t\n]\\s*");
to limit strings (\\s) between newline or tab characters.

Resources