How to add a newline to a variable? - variables

I'm trying to append a trailing newline to a variable like:
data := "text"
Clipboard := data "\n"
But that leads to a data with literal \n. All other tries without quotation marks leads to errors.

Instead of using a backslash \ AHK uses a backtick `.
So you'd do a line feed character with `n, or a carriage return with `r, or a horizontal tab with `t, and so on.
data := "text"
Clipboard := data "`n"

Related

how to write string literal with new lines in Pharo

How do you write a string literal with new line characters in Pharo 9? I tried the following but neither of them inserted the new line:
a := 'paragraph1\n\nparagraph2'.
a := 'paragraph1\\n\\nparagraph2'.
The only way I could see to do it was through concatenation like so:
a := 'paragraph' ,
(String with: Character cr with: Character cr),
'new paragraph' ,
(String with: Character cr with: Character cr)
Is there a simpler (and shorter) way to do this?
You just do your line:
multiLineString := 'paragraph1
paragraph2
paragraph3'.
Pharo (as any other Smalltalk AFAIK) has multiline strings, you do not need any special notation as in Python or others.
EDIT: Note that while my example will be a literal, yours will not (there will be 2 literals there, and the resulting string will not be a literal.
EDIT 2: There is also String cr.
EDIT 3: It can also be constructed with streams:
myMultiLineString := String streamContents: [ :stream |
stream
nextPutAll: 'paragraph1'; cr;
nextPutAll: 'paragraph2'; cr ]
You can use the <n> placeholder in your String and send it the expandMacros message - this will expand the placeholder to the platform line separator(s):
a := 'paragraph1<n>paragraph2' expandMacros.
expandMacros and its variants also accept placeholders for tabs, cr, lf and parameters. See the comment to String>>expandMacrosWithArguments: for more details.

Remove double quotes from Data

I am getting data in csv file with double quotes around string columns but while reading csv file using U-sql i am getting errors because of double quotes in data as well.
I am thinking of replacing double quotes which is in data at first step then read that file but not sure how to do that as we have double quotes everywhere.
Any suggestions would be appreciated or if someone can help me giving the powershell or .net code to do the same that would be great help as I am not good in .net or powershell.
Sample Data
“Name”;”Department”
“Abc”;”Education”Teaching”
“Cde”;”Test”Another”
It should be
“Name”;”Department”
“Abc”;”EducationTeaching”
“Cde”;”TestAnother”
You can use a regex find/replace in Visual Studio Code. For example (and assuming that the data only contains letters, you can edit the regex as needed):
Find regex: "([a-zA-Z]+)"([a-zA-Z]+)"
Replace string: "$1$2"
Input string: "Name";"Department" "Abc";"Education"Teaching" "Cde";"Test"Another"
Output string: "Name";"Department" "Abc";"EducationTeaching" "Cde";"TestAnother"
So it seems that your quotes are not the standard [Char]34. Instead they are [Char]8220; [Char]8221
So we need to do a replace in powershell
$TEST = #"
“Name”;”Department” “Abc”;”Education”Teaching” “Cde”;”Test”Another”
"#
$TEST | %{
$_ = $_ -replace [char]8220, '"'
$_ = $_ -replace [char]8221, '"'
$_ -replace '"([a-zA-Z]+)"([a-zA-Z]+)"','"$2 $1"'
}
this would make the output :
"Name";"Department" "Abc";"Teaching Education" "Cde";"Another Test"
You could also do this in a custom row processor. Have the initial data read the CSV file into a variable as a single column row (raw data). Then pass each row through a row processor to parse the data and remove the offending characters. I've done something similar for handling Fixed Width text files.

How to add asterisk to a list of filenames and then make it a line using Notepad++

I have a list of file names (about 4000).
For example:
A-67569
H-67985
J-87657
K-85897
...
I need to put an asterisk before and after each file name. And then make it a line format.
Example:
*A-67569* *H-67985* *J-87657* *K-85897* so on...
Note that there is a space between filenames.
Forgot to mention, I'm trying to do this with Notepad++
How can I do it?
Please advise.
Thanks
C# example for list to string plus edits
List<string> list = new List<string> { "A - 67569"), "H-67985", "J-87657", "K-85897"};
string outString = "";
foreach(string item in list)
{
outString += "*" + item + "* ";
}
content of outstring: *A - 67569* *H-67985* *J-87657* *K-85897*
Use the Replace of your Notedad++ (Search > Replace..)
Select Extended (\n \r \t \0 \x...) on the bottom of the Replace window
In the field Find what write '\r\n' and in the field Replace with write * *
Replace all
Note, that you should manually place the single asterisk before the first and after the last words.
If this won't work, in step 2. instead of \r\n try to use only \n or \r.
You can use Regular expression in the search Mode.
Find what:
(\S+)(\R|$)
Replace with:
*$1
Note the space after de number one
For the archive
A-67569
H-67985
J-87657
K-85897
Output:
*A-67569 *H-67985 *J-87657 *K-85897
Explication of regex:
(\S+) Mean find one or more caracters is not a blank.
(\R|$) Mean find any end of line or end of file
(\S+)(\R|$) Mean find any gorup of caracters not blank ho end with end of line or end of file.
Explication of Replace with
When you use the $ simpbol, you are using a reference to the groups finded, $1 is the first group, in this case the group (\S+).

How can I replace Pipe (|) with space using regexp_replace in Teradata?

I would like to replace all pipes and line breaks with space in a free text field in my data base.
My current approach looks like the following:
SELECT
ID,
REGEXP_REPLACE(REGEXP_REPLACE(FREETEXT,'|',‘ ‘),‘\n',' ')
FROM TABLE
My idea is to replace the pipes | with a space and then the results get checked again and all linebreaks are replaced. Problem now is that there are still pipes in there which messes up the CSV since my delimter for that is |.
Hope anyone can help me out here.
PS: I am not able to change the delimter to something else.
The pipe symbol is a special character in a Regular Expression, splitting it into multiple alternatives, thus you must escape it.
If you want to replace all pipe and line break characters you don't have to nest:
RegExp_Replace(FREETEXT,'[\|\n\r]',' ')
\| pipe 0x7C
\n line feed 0x0A
\r carriage return 0x0D
But as those are single characters you can simply use
OTranslate(FREETEXT, '7C0A0D'xc,' ')
Only if you want to replace consecutive occurences of those characters with a single space you need a RegEx:
RegExp_Replace(FREETEXT,'[\|\n\r]+',' ')

Write multiple lines to text file with '\n'

I have a program that iterates over all lines of a text file, adds spaces between the characters, and writes the output to the same file. However, if there are multiple lines in the input, I want the output to have separate lines as well. I tried:
let text = format!(r"{}\n", line); // Add newline character to each line (while iterating)
file.write_all(text.as_bytes()); // Write each line + newline
Here is an example input text file:
foo
bar
baz
And its output:
f o o\n b a r\n b a z
It seems that Rust treats "\n" as an escaped n character, but using r"\n" treats it as a string. How can I have Rust treat \n as a newline character to write multiple lines to a text file?
Note: I can include the rest of my code if you need it, let me know.
Edit: I am on Windows 7 64 bit
The problem is the 'r' in front of your string. Remove it and your program will print newlines instead of '\n'.
Also note that only most Unices use '\n' as newline. Windows uses "\r\n".