White spaces before and post equal sign, brackets and other - visual-studio-2012

I use Visual studio 2012 and plugin Visual assist X ver. 1916. I have two questions.
1) When I write equal sign (=), I want automatic insertion of white spaces before and after the sign (I must always insert by space on keyboard...). Is it possible?
Example:
int variable=167;
->
int variable = 167;
or
"=" -> " = "
2) I want automatic insertion of white space before and after brackets and before and after commas. Is it possible?
Example:
void fun(int param1,int param2);
->
void fun ( int param1, int param2 );

VASSISTX -> Tools -> Edit VA Snippets.
Add new one with shortcut "="(without the "") and in the body write " = "(without the ""). Same goes for the rest of your requirements, the rule is simple: in shortcut write the symbol you want to be identified when typed and in the body what you actually want to be printed.

Related

How to wrap some text in vim with '', "", (), [], {}, etc?

I'm new to vim. And I'm pressing too many buttons doing basic text wrapping:
string -> "string"
long string with many words -> 'long string with many words'
a + b * c -> (a + b) * c
(elem0, elem1, elem2) -> [elem0, elem1, elem2] (optional)
I'm doing all that manually: go to begin, Insert mode, press key, Normal mode, (the same for second character).
How to do it faster? E.g.: visually select the text, smart-wrap it with what you need. Or even without visual selection.
string -> "string"
ciw"<C-r>""
long string with many words -> 'long string with many words'
veeeeec'<C-r>"'
a + b * c -> (a + b) * c
vwwc(<C-r>")
(elem0, elem1, elem2) -> [elem0, elem1, elem2] (optional)
"edibxs[<C-r>e]
That one is a bit more complicated:
"edib cut the content of those parentheses into
an arbitrary register, here I used "e
xs cut the closing parenthese then cut the opening one
and enter insert mode
[<C-r>e] insert the opening bracket, followed by the content of
register e, followed by the closing bracket
But yeah, use Tim Pope's Surround.
You can use visuall mode for this. For example you have string. ^ will be cursor positioning. Start in normal mode
1. string # press viwc(your word will be selected and deleted to unnamed register)
^
2. # press " and then <C-r>"(this will paste your selected text) and then press again "
This method can be with any surrounding parenthesis or brackets and with any number of words. you just need to change your selection in visual mode

System String^ adding characters to stack (Visual C++)

I'm trying to get characters from a String^ to put into a stack to use later, but when I check what actually gets put in it always has a number in front of it which messes up using it later (e.g. If I try to get a "-" character from within my string it shows as " 45 "-" ").
String^ input = "8-2";
char Temp = input[1];
The Temp variable will show as = 45 "-"
I'd like it to just save to the char as "-" only so I add it to a stack and call it later with Peek() but I can't figure out how.
45 is the ASCII code of the character -. It's showing you your data as both integer and character.
"char" (when using C++/CLI) is a C/C++ type (a one-byte representation of a 'character'). It's not a .NET type. Try Char (e.g. System::Char) instead and see if that works.

How to split sentence in visual c++?

Hi I'm currently using Microsoft Visual Studio 2015, c++ with forms and having trouble with split. I have tried many code exemples (all of them was on console application and I didn't know how to make them work for me). This is how at least I imagining code (simplified code exemple below). There is a string that you take from textBox1, then you split that string where there is a dot, and putting them in table.
String ^ text = textBox1->Text;
text->ToString()->Split('.');
tableGrid->Rows[0]->Cells[1]->Value = text;
Split does not modify text here. Instead it returns an array of the split results.
You need to capture and use the results so something like this:
String^ text = textBox1->Text;
cli::array<String^>^ pieces = text->Split('.');
for (int i = 0; i < pieces->Length; ++i) {
// Add pieces[i] to the table. Perhaps:
tableGrid->Rows[0]->Cells[i]->Value = pieces[i];
}

C++ Replacing non-alpha/apostrophe with spaces in a string

I am reading in a text file and parsing the words into a map to count numbers of occurrences of each word on each line. I am required to ignore all non-alphabetic chars (punctuation, digits, white space, etc) except for apostrophes. I can figure out how to delete all of these characters using the following code, but that causes incorrect words, like "one-two" comes out as "onetwo", which should be two words, "one" and "two".
Instead, I am trying to now replace all of these values with spaces instead of simply deleting, but can't figure out how to do this. I figured the replace-if algorithm would be a good algorithm to use, but can't figure out the proper syntax to accomplish this. C++11 is fine. Any suggestions?
Sample output would be the following:
"first second" = "first" and "second"
"one-two" = "one" and "two"
"last.First" = "last" and "first"
"you're" = "you're"
"great! A" = "great" and "A"
// What I initially used to delete non-alpha and white space (apostrophe's not working currently, though)
// Read file one line at a time
while (getline(text, line)){
istringstream iss(line);
// Parse line on white space, storing values into tokens map
while (iss >> word){
word.erase(remove_if(word.begin(), word.end(), my_predicate), word.end());
++tokens[word][linenum];
}
++linenum;
}
bool my_predicate(char c){
return c == '\'' || !isalpha(c); // This line's not working properly for apostrophe's yet
}
bool my_predicate(char c){
return c == '\'' || !isalpha(c);
}
Here you're writing that you want to remove the char if it is and apostrophe or if it is not an alphabetical character.
Since you want to replace these, you should use std::replace_if() :
std::replace_if(std::begin(word), std::end(word), my_predicate, ' ');
And you should correct your predicate too :
return !isalpha(c) && c != '\'';
You could use std::replace_if to pre-process the input line before sending it to the istringstream. This will also simplify your inner loop.
while (getline(text, line)){
replace_if(line.begin(), line.end(), my_predicate, ' ');
istringstream iss(line);
// Parse line on white space, storing values into tokens map
while (iss >> word){
++tokens[word][linenum];
}
++linenum;
}

Standard ML string to a list

Is there a way in ML to take in a string and output a list of those string where a separation is a space, newline or eof, but also keeping strings inside strings intact?
EX) hello world "my id" is 5555
-> [hello, world, my id, is, 5555]
I am working on a tokenizing these then into:
->[word, word, string, word, int]
Sure you can! Here's the idea:
If we take a string like "Hello World, \"my id\" is 5555", we can split it at the quote marks, ignoring the spaces for now. This gives us ["Hello World, ", "my id", " is 5555"]. The important thing to notice here is that the list contains three elements - an odd number. As long as the string only contains pairs of quotes (as it will if it's properly formatted), we'll always get an odd number of elements when we split at the quote marks.
A second important thing is that all the even-numbered elements of the list will be strings that were unquoted (if we start counting from 0), and the odd-numbered ones were quoted. That means that all we need to do is tokenize the ones that were unquoted, and then we're done!
I put some code together - you can continue from there:
fun foo s =
let
val quoteSep = String.tokens (fn c => c = #"\"") s
val spaceSep = String.tokens (fn c => c = #" ") (* change this to include newlines and stuff *)
fun sepEven [] = []
| sepEven [x] = (* there were no quotes in the string *)
| sepEven (x::y::xs) = (* x was unquoted, y was quoted *)
in
if length quoteSep mod 2 = 0
then (* there was an uneven number of quote marks - something is wrong! *)
else (* call sepEven *)
end
String.tokens brings you halfway there. But if you really want to handle quotes like you are sketching then there is no way around writing an actual lexer. MLlex, which comes with SML/NJ and MLton (but is usable with any SML) could help. Or you just write it by hand, which should be easy enough in this case as well.

Resources