I am trying to write a google app script, which will find and replace specific words with others in google docs...
I would like " hello " (space, hello, space) to be replaced by " R1 " (space, R1, space)
And if there is any punctuation mark after hello like a period, comma or question mark it should be the same logic:
" hello " to be replaced by " R1 "
" hello. " to be replaced by " R1. "
" hello, " to be replaced by " R1, "
" hello? " to be replaced by " R1? "
So I used the following:
function docReplace() {
var body = DocumentApp.getActiveDocument().getBody();
body.replaceText(" hello ", " R1 ");
body.replaceText(" hello. ", " R1. ");
body.replaceText(" hello, ", " R1, ");
body.replaceText(" hello? ", " R1? ");
}
Unfortunately this doesn't work, as "." , "," and "?" are regex symbols.
Then, I tried this:
function docReplace() {
var body = DocumentApp.getActiveDocument().getBody();
body.replaceText(" hello ", " R1 ");
body.replaceText(" hello\. ", " R1. ");
body.replaceText(" hello\, ", " R1, ");
body.replaceText(" hello\? ", " R1? ");
}
But still doesn't work. Commas and Question marks return as periods.
I would appreciate if anyone could help with the correct code.
You want to achieve the following replacement using Google Apps Script. In this sample, ## was used as the separator of the values.
From
## hello ##
## hello. ##
## hello, ##
## hello? ##
To
## R1 ##
## R1. ##
## R1, ##
## R1? ##
If my understanding is correct, how about this modification? In this modification, \., \, and \? are modified to \\., \\, and \\?, respectively.
Modified script:
function docReplace() {
var body = DocumentApp.getActiveDocument().getBody();
body.replaceText(" hello ", " R1 "); // Modified
body.replaceText(" hello\\. ", " R1. "); // Modified
body.replaceText(" hello\\, ", " R1, "); // Modified
body.replaceText(" hello\\? ", " R1? "); // Modified
}
Reference:
replaceText(searchPattern, replacement)
If I misunderstood your question and this was not the result you want, I apologize.
Related
I have this code in html, which has a form to send files, but I would like to read these files directly from a path on the computer, how do I do that? I'm new to the language
Thanks
`
const char* serverIndex =
"<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>"
"<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>"
"<input type='file' name='update'>"
"</form>"
"<div id='prg'>Progresso: 0%</div>"
"<script>"
"$('form').submit(function(e){"
"e.preventDefault();"
"var form = $('#upload_form')[0];"
"var data = new FormData(form);"
" $.ajax({"
"url: '/update',"
"type: 'POST',"
"data: data,"
"contentType: false,"
"processData:false,"
"xhr: function() {"
"var xhr = new window.XMLHttpRequest();"
"xhr.upload.addEventListener('progress', function(evt) {"
"if (evt.lengthComputable) {"
"var per = evt.loaded / evt.total;"
"$('#prg').html('Progresso: ' + Math.round(per*100) + '%');"
"}"
"}, false);"
"return xhr;"
"},"
"success:function(d, s) {"
"console.log('Sucesso!')"
"},"
"error: function (a, b, c) {"
"}"
"});"
"});"
"</script>";
`
Example:
i would like to read this file
file:///C:/Users/Matheus/Desktop/test.bin
Below special characters are present in a csv file.
" – " , " ’ " , " ‘ "
I am already using option("encoding","ISO-8859-1") in the read statement in order to handle few other scenarios (without this option few spaces are getting read as – ).
But by using this option,
" Samsung – 22 " is getting read as " Samsung ? 22 "
" ‘World’ " is getting read as " ?World? "
I have a text like below and I am trying to convert it into a CSV file. How can I do it?
[
[“Date”, “Description”, “Deposits”, “Withdrawals”, “Balance”, " "]
,
[“4 Mar '22”, “DIRECT CREDIT SUPPORTPYMTD230576800#”, “$4,800.00”, " ", “$27,727.50”, " "]
,
[“22 Feb '22”, “DIRECT CREDIT 31/03/2021 D569582240# INC”, “$11.13”, " ", “$22,927.50”, " "]
]
Thank you.
Problem
In Enterprise Architect 7.1.834 in the code generation templates it is possible to print all the parent packages that a class belongs to in the scope of the File template?
The reason this is needed is to generate multi-include guards compliant with my companies coding standard
What doesn't work
I have tried both:
%list="Namespace__Notes" #separator="-"%
and
%packageName%
The output of both only prints the top-level parent package (Package1) but I would like to see:
Package1-Package2-Package3
Has anyone found a way to do this?
Namepace__Notes
Namepace__Notes is a custom template with Namepace type, the contents are ar follows
%PI=""%
%packageName%
[Edit] Dirty Solution
My current (dirty) solution is to mangle the file-path. Am I missing something?
The code:
$l_backslash = %REPLACE("\z","z","")%
$filepath = %filePath%
$upper_filepath = %TO_UPPER($filepath)%
$upper_package_as_path = $l_backslash + %TO_UPPER(packageName)% + $l_backslash
$upper_package_base_len = %LENGTH(packageName)%
$package_path_pos = %FIND($upper_filepath,$upper_package_as_path)%
%if $package_path_pos != "-1" and $package_path_pos != "0"%
$upper_filepath = %MID($upper_filepath,$package_path_pos)%
%endIf%
$file_define = "_" + $upper_filepath + "__"
$file_define = %REPLACE($file_define,".","_")%
$file_define = %REPLACE($file_define,$l_backslash,"_")%
$file_define = %REPLACE($file_define,"/","_")%
$body += "/**************************************************************************//**"
$body += "\n * \file " + %fileName%
$body += "\n *"
$body += "\n * \brief " + %elemType% + " " + %className% + " header file"
$body += "\n *"
$body += "\n * \author " + %classAuthor ? value : "<unknown>"%
$body += "\n *"
$body += "\n *****************************************************************************/"
$body += "\n"
$body += "\n#ifndef " + $file_define
$body += "\n#define " + $file_define
$body += "\n"
%packagePath% gives you the dot-separated package hierarchy, while %classQualName% yields the ::-separated class hierarchy (for inner classes).
This is for the current version, I don't know whether these macros were present as far back as 7.1. You should seriously consider upgrading, as the current version is 9.3 and EA is backwards-compatible wrt project contents.
In EA 10 %packagePath% also gives only top level package in File template
[Edit] Another dirty and partial solution.
I'v made a new custom templates, Namespace__fullName:
$prevName = %list="Namespace__fullName"%
%if $prevName != ""%
%packageName%::$prevName
%else%
%packageName%
%endIf%
;
and Class__fullQualName:
%list="Namespace__fullName"%::%classQualName%
This will work in simple cases when the source file contains only 1 class (possibly with nested items) and, therefore, only 1 namespaces hierarchy.
Is this possible?
I am trying to port an old professor's demo-game into a web-playable format for fun, and he had setup all the graphics in the XPM format.
Is there some way to load XPM files directly into an HTML5 canvas? I could probably get by with loading them into an image editor and converting...but I'd rather stay as true to the original source as possible.
You could probably write some sort of parser for XPM in JavaScript and render canvas pixels using a similar approach to this question, however I think it'd be more efficient just to use something like ImageMagick and do a one off conversion:
mogrify -format png *.xpm
I made a little plugin to do this, there's a lot to improve but maybe it can help you... you can see the demo here: http://cortezcristian.com.ar/xpm2canvas/
You can also play with the demo in this fiddle: http://jsfiddle.net/crisboot/aXt3G/
<script src="./js/libs/jquery-1.7.1.min.js"></script>
<script src="./js/jquery.xpm2canvas.js"></script>
<script>
var pseudoXMP = [
/* <Values> */
/* <width/cols> <height/rows> <colors> <char on pixel>*/
"40 40 6 1",
/* <Colors> */
" c none",
". c #ffffff",
"X c #dadab6",
"o c #6c91b6",
"O c #476c6c",
"+ c #000000",
/* <Pixels> */
" ",
" ",
" ",
" . .X..XX.XX X ",
" .. .....X.XXXXXX XX ",
" ... ....X..XX.XXXXX XXX ",
" .. ..........X.XXXXXXXXXXX XX ",
" .... ........X..XX.XXXXXXXXX XXXX ",
" .... ..........X.XXXXXXXXXXX XXXX ",
" ooOOO..ooooooOooOOoOOOOOOOXX+++OO++ ",
" ooOOO..ooooooooOoOOOOOOOOOXX+++OO++ ",
" ....O..ooooooOooOOoOOOOOOOXX+XXXX++ ",
" ....O..ooooooooOoOOOOOOOOOXX+XXXX++ ",
" ..OOO..ooooooOooOOoOOOOOOOXX+++XX++ ",
" ++++..ooooooooOoOOOOOOOOOXX+++ +++ ",
" +++..ooooooOooOOoOOOOOOOXX+++ + ",
" ++..ooooooooOoOOOOOOOOOXX+++ ",
" ..ooooooOooOOoOOOOOOOXX+++ ",
" ..ooooooooOoOOOOOOOOOXX+++ ",
" ..ooooooOooOOoOOOOOOOXX+++ ",
" ..ooooooooOoOOOOOOOOOXX+++ ",
" ..oooooOooOOoOOOOOOXX+++ ",
" ..oooooooOoOOOOOOOOXX+++ ",
" ..ooooOooOOoOOOOOXX+++ ",
" ..ooooooOoOOOOOOOXX++++ ",
" ..o..oooOooOOoOOOOXX+XX+++ ",
" ...o..oooooOoOOOOOXX++XXX++ ",
" ....OO..ooOooOOoOOXX+++XXXX++ ",
" ...oo..+..oooOoOOOXX++XXooXXX++ ",
" ...ooo..++..OooOOoXX+++XXooOXXX+ ",
" ..oooOOXX+++....XXXX++++XXOOoOOXX+ ",
" ..oooOOXX+++ ...XXX+++++XXOOooOXX++ ",
" ..oooOXXX+++ ..XX+++ +XXOOooOXX++ ",
" .....XXX++++ XXXXXXX++ ",
" ....XX++++ XXXXXXX+ ",
" ...XX+++ XXXXX++ ",
" ",
" ",
" ",
" "];
$(document).ready(function(){
$('#xmp2canvas').xpm2canvas({xpm:pseudoXMP});
});
</script>
IIRC, the rendering context for a canvas element in such a context relies on manipulating the src attribute of an embedded img tag. As such, presumably XPM files only stand a chance of working if the browser in question supports them.
The best way to check this would be to test it. The accepted answer for this question contains some code that should help:
importing image on canvas html5