Replace with a different segment - scripting

I have a code which is having around 6000 lines in C++.
As a part of code refactoring, I'm required to modify all the output lines in this code.
Eg:
Currently, existing lines look like this -
cout<<"The string value is - " << sStringVal;
My modification is to add the class name in each cout statement, like -
cout<<"CFlowController: The string value is - "<< sStringVal;
There are around 3900 output lines which require this change. Can
anyone suggest a script or how to do this apart from the manual
replacement?

Related

Visual Studio Code Snippet Variable Transform not working

I'm trying to make a snippet that inserts the last two directorys of the current filepath.
My code:
${TM_DIRECTORY/\\(.*)\\([a-zA-Z]+)\\([a-zA-Z]+)/$1\\$2/}
So when Filepath is
"...\htdocs\projectname\src"
the output should be
"projectname\src".
But instead I get this result:
${TM_DIRECTORY/(.*)\\([a-zA-Z]+)\\([a-zA-Z]+)/$1/}
What am I doing wrong?
Problem:
The issue is the code converts \\ to \. For example if you want to write \w, then you have to write \\win snippet.
The same way.. You have to write \\\\ in snippet json, so that it shall convert into //.
Solution:
${TM_DIRECTORY/.*?\\\\([a-zA-Z]+\\\\[a-zA-Z]+)$/$1/}
or, I think you should use \w instead of [a-zA-Z] because the directory name can contain some characters like - or _ etc.
${TM_DIRECTORY/.*?\\\\(\\w+\\\\\\w+)$/$1/}

How can I sum two numbers in Latex with my own command?

I have to sum two numbers (integers) in LaTeX. I also have to "print" the process of sum. So it would look like 5+2=7 in text. Any ideas?
My code so far:
\newcommand{\Sum}
{\newcounter{cnt}
\setcountter{cnt}{1+1}
}
In LaTeX, first you have to define a counter with:
\newcounter{countername}
Then you can put a value in this counter with:
\setcounter{countername}{<value>}
where <value> is an integer. Or you can add one to this counter with:
\stepcounter{countername}
or you can add some arbitrary value to this counter with:
\addtocounter{countername}{<value>}
Then, to access this counter you use:
\value{countername}
so you can, for example, make calculations with this counter:
\setcounter{anothercounter}{%
\numexpr\value{countername}+10\relax%
}
Then, when you need to print the value of this counter to the pdf file, you can you the mighty \the:
\the\value{countername}
or you can use one of these:
\arabic{countername}
\roman{countername}
\Roman{countername}
\alph{countername}
\Alph{countername}
Perhaps a different syntax can be in order; instead of supplying each argument to calculate a sum, you can supply the operator with the operands. This allows you to be a little more flexible in terms of the input and also provide more functionality:
\documentclass{article}
\usepackage{xfp}
\NewDocumentCommand{\showcalculation}{o m}{$
\IfValueTF{#1}
{#1}{#2} = \fpeval{#2}
$}
\begin{document}
\showcalculation{7+3}
\showcalculation{1+2-3+4}
\showcalculation[22 \div 7]{22 / 7}
\showcalculation[10 \times 3^{7 - 7}]{10 * 3 ^ (7 - 7)}
\end{document}
The optional argument for \showcalculation uses a LaTeX formatting for the printable calculation.
I've managed to solve the problem.
\newcommand{\Sum} [2] {#1 + #2 = \the\numexpr #1 + #2 \relax \\}
And then I use my command as:
\Sum {7} {3}

How would I create a function in objective-c that would correctly output the results of in mathematical precedence?

I want to create a mathematical calculator in objective-C. I need it to run
through a command line. The user will enter an equation like 4 + 2 * 12 etc. The output should calculate the 2 and 12 first because they are times by. How would I create a command line program that creates output based on mathematical order or precedence. for example solving whats in the brackets first then anything that is multiplied and or divided by etc etc.
there are multiple programs available online for this here is just one http://www.wikihow.com/Make-a-Command-Prompt-Calculator, in the CMD line you can specify precedence by simply using parenthesis like the following C:> set /a ((2*12)+4) obviously replacing hard coded values with that passed to a variable.

idl strange symbols in file

I've written several IDL programs to analyse some data. To keep it simple the programs read in some time varying data and calculate the fourier spectrum. This spectrum is written to file using this code:
openw,3,filename
printf,3,[transpose(freq),transpose(power)],format='(e,e)'
close,3
The file is then read by another program using this code:
rdfloat,filename,freq,power,/double
The rdfloat procedure can be found here: http://idlastro.gsfc.nasa.gov/
The error i get when trying to read the a file is: "Input conversion error. Unit: 101"
When i delve in to the file being read, i notice several types of unrecognised characters. I dont know if these are a result of the writing to the file or some thing else related to the number of files being created (over 300 files)
These symbols/characters are in the place of a single number:
< dle> < dc1> < dc2> < dc3> < dc4> < can> < nak> < em> < soh> < syn>
Example of what appears in the file being read, Note they are not consecutive lines.
7.7346< dle>18165493007e+01 8.4796811549010105e+00
7.7354408697119453e+01 1.04459538071< dc2>1749e+01
7.7360701595839< can>28e+01 3.0447318983094189e+00
Whenever I run the procedures that write the files, there is always at least one file that has some or all of these characters. The file/s that contains these characters is always different.
Can anyone explain what these symbols are and what I might be doing to create them as well as how to ensure they are not written to file?
I see two things that may be causing a problem. But first, I want to suggest a few tips.
When you open a file, it is useful to use the /GET_LUN keyword because it allows IDL to find and use a logical unit number (LUN) that is available (e.g., in case you left LUN 3 open somewhere else). When you print formatted data, you should specify the total width and number of decimal places. It will make things easier because then you need not worry about changing spacings between numbers in a file.
So I would change your first set of code to the following (or some variant of the following):
OPENW,gunit,filename[0],/GET_LUN,ERROR=err
FOR j=0L, N_ELEMENTS(freq) - 1L DO BEGIN
PRINTF,gunit,freq[j],power[j],FORMAT='(2e20.12)'
ENDFOR
FREE_LUN,gunit ;; this is better than using the CLOSE routine
So the first potential issue I see is that if your variable power was calculated using something like FFT.pro, then it will be a complex float or complex double, depending on the input and keywords used.
The second potential issue may be due to an incorrect format statement. You did not tell PRINTF how many columns or rows to expect. It might not know how to handle the input properly, so it guesses and may result in those characters you show. Those characters may be spacing characters due to the vague format statement or the software you are using to look at the files (e.g., I would not recommend using Word to open text files, use a text editor).
Side Note: You can open and read the file you just wrote in a similar fashion to what I showed above, but changed to the following:
n = FILE_LINES(filename[0])
freq = DBLARR(n)
power = DBLARR(n)
OPENR,gunit,filename[0],/GET_LUN,ERROR=err
FOR j=0L, N_ELEMENTS(freq) - 1L DO BEGIN
READF,gunit,freq[j],power[j],FORMAT='(2e20.12)'
ENDFOR
FREE_LUN,gunit ;; this is better than using the CLOSE routine

How to split lines in Haskell?

I have made a program which takes a 1000 digit number as input.
It is fixed, so I put this input into the code file itself.
I would obviously be storing it as Integer type, but how do I do it?
I have tried the program by having 1000 digits in the same line. I know this is the worst possible code format! But it works.
How can assign the variable this number, and split its lines. I read somewhere something about eos? Ruby, end of what?
I was thinking that something similar to comments could be used here.
Help will be appreciated.
the basic idea is to make this work:
a=3847981438917489137897491412341234
983745893289572395725258923745897232
instead of something like this:
a=3847981438917489137897491412341234983745893289572395725258923745897232
Haskell doesn't have a way to split (non-String) literals across multiple lines. Since Strings are an exception, we can shoehorn in other literals by parsing a multiline String:
v = read
"32456\
\23857\
\23545" :: Integer
Alternately, you can use list syntax if you think it's prettier:
v = read . concat $
["32456"
,"24357"
,"23476"
] :: Integer
The price you pay for this is that some work will be done (once) at runtime, namely, the parsing (e.g. read).