Vs code select text between quotes - visual-studio-code

I have a vast array list like below
$data= [
'user_name' => 's',
'user_place' => 'a',
'address_list_code' => 's',
'block_number' => 3,
];
so I want to replace the key string with all uppercase.I know to convert selected text to uppercase using vs code shortcut Ctl+Alt+u and it works.
But I want to select only all keys in between a single quote and make it uppercase so the expected output is
[
'USER_NAME' => 's',
'USER_PLACE' => 'a',
'ADDRESS_LIST_CODE' => 's',
'BLOCK_NUMBER' => 3,
];
Even I tried this extension but not suceded to select all text in between single quotes
https://marketplace.visualstudio.com/items?itemName=dbankier.vscode-quick-select&ssr=false#version-history

Check out this fiddle : https://jsfiddle.net/m82ycfxw/
I made a normal JS code to convert the desired text to upper case.
This might be a temporary thing but I hope this will work for you.
let str = `
$data= [
'user_name' => 's',
'user_place' => 'a',
'address_list_code' => 's',
'block_number' => 3,
]
`;
var regex = /'[a-z_]+' =>/g;
str = str.replace(regex, foundText => {
return foundText.toUpperCase();
});
console.log(str);
Just change the str variable. Put all your complete data object inside backticks (` `)and run the code.

The extension Select By could help.
Place cursors at the start of the lines where you want to Uppercase text
with MoveBy: Move cursors based on regex move to the next '
with SelectBy: Mark positions of cursors
with MoveBy: Move cursors based on regex move to the next '
with SelectBy: Mark positions of cursors (create selections)
execute: Transform to Uppercase
Esc to exit multi Cursor

Sure, you can do this natively:
In settings.json, temporarily remove _ as a word separators (e.g. "editor.wordSeparators": "!##$%^&*()-=+[{]}\\|;:'\",.<>/?,) (Notice no _)
.
Place cursors at beginnings of all desired lines.
Right arrow to move all cursors within the quotes.
Execute command expand selection. Since you turned off _ as a word delimiter, this will expand to fill the quotes; otherwise, all the keys would need to have the same number of words for this to work.
Execute upper case.
In settings.json re-add _ to word separators.

Easy with Find and Replace. See regex101 demo
Find: (^\s+')([^']*)'
Replace: $1\U$2'
The \U will uppercase the following capture group $2.
Starting the find at the beginning of the line with ^ makes it easy to target just the "keys" (the first '-delimmited strings) and not the other following strings.

Related

String replacement array of strings in Scala

I'm confused as to how i can create a new string on the basis of another, replacing some values of the original string,
If i have
Array(easy_id, 1_sum(term_invested_points), 1_sum(std_invested_points), 1_sum(std_used_points), 1_sum(term_used_points), 9_sum(term_invested_points))
and want to produce
Array(easy_id, 1_sum_term_invested_points_, 1_sum_std_invested_points_, 1_sum_std_used_points_, 1_sum_term_used_points_, 9_sum_term_invested_points_)
i.e substitute brackets for underscores in my array.
I have tried
array.columns.map{ case "" => "("; case x => x }
However this just produces the original array, why doesn't it work?
You could do something like this:
val arr = Array(
"easy_id",
"1_sum(term_invested_points)",
"1_sum(std_invested_points)",
"1_sum(std_used_points)",
"1_sum(term_used_points)",
"9_sum(term_invested_points)"
)
arr.map(_.replaceAll("\\(|\\)", "_"))
Map inside the array and replace all opening or closing brackets with underscores (brackets need to be escaped with backslashes as they are Regex special characters).

Issue with eval_in_page - Trying to interpolate an array

my #para_text = $mech->xpath('/html/body/form/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/table/tbody/tr[3]/td/div/div/div', type => $mech->xpathResult('STRING_TYPE'));
#BELOW IS JUST TO MAKE SURE THE ABOVE CAPTURED THE CORRECT TEXT
print "Look here: #para_text";
$mech->click_button( id => "lnkHdrreplyall");
$mech->eval_in_page('document.getElementsByName("txtbdy")[0].value = "#para_text"');
In the last line of my code I need to put the contents of the #para_text array as the text to output into a text box on a website however from the "document" till the end of the line it needs to be surrounded by ' ' to work. Obviously this doesnt allow interpolation as that would require " " Any ideas on what to do?
To define a string that itself contains double quotes as well as interpolating variable values, you may use the alternative form of the double quote qq/ ... /, where you can choose the delimiter yourself and prevent the double quote " from being special
So you can write
$mech->eval_in_page(qq/document.getElementsByName("txtbdy")[0].value = "#para_text"/)

How to understand such this kind of variable to combine _ and other charcters in Perl?

How to understand such this kind of value in Perl?
my %opt = ( _argv => join(" ",#ARGV),_cwd = cwd()).
Are _argv and _cwd both strings?
From the reference:
The => operator (sometimes pronounced "fat comma") is a synonym for the comma except that it causes a word on its left to be interpreted as a string if it begins with a letter or underscore and is composed only of letters, digits and underscores. This includes operands that might otherwise be interpreted as operators, constants, single number v-strings or function calls. If in doubt about this behavior, the left operand can be quoted explicitly.
my %hash = ('a' => 'b', 'c' => 'd');
can be written as
my %hash = (a => 'b', c => 'd');
thanks for everyone, Now I think _argv and _cwd both are just a variable name, equals to "_argv" and "_cwd".

Is it possible to match any character that is not ']' in PATINDEX?

I need to find the index of the first character that is not ]. Normally to match any character except X, you use the pattern [^X]. The problem is that [^]] simply closes the first bracket too early. The first part, [^], will match any character.
In the documentation for the LIKE operator, if you scroll down to the section "Using Wildcard Characters As Literals" it shows a table of methods to indicated literal characters like [ and ] inside a pattern. It makes no mention of using [ or ] inside double brackets. If the pattern is being used with the LIKE operator, you would use the ESCAPE clause. LIKE doesn't return an index and PATINDEX doesn't seem to have a parameter for an escape clause.
Is there no way to do this?
(This may seem arbitrary. To put some context around it, I need to match ] immediately followed by a character that is not ] in order to locate the end of a quoted identifier. ]] is the only character escape inside a quoted identifier.)
This isn't possible. The Connect item PATINDEX Missing ESCAPE Clause is closed as won't fix.
I'd probably use CLR and regular expressions.
A simple implementation might be
using System.Data.SqlTypes;
using System.Text.RegularExpressions;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlInt32 PatIndexCLR(SqlString pattern, SqlString expression)
{
if (pattern.IsNull || expression.IsNull)
return new SqlInt32();
Match match = Regex.Match(expression.ToString(), pattern.ToString());
if (match.Success)
{
return new SqlInt32(match.Index + 1);
}
else
{
return new SqlInt32(0);
}
}
}
With example usage
SELECT [dbo].[PatIndexCLR] ( N'[^]]', N']]]]]]]]ABC[DEF');
If that is not an option a possible flaky workaround might be to substitute a character unlikely to be in the data without this special significance in the grammar.
WITH T(Value) AS
(
SELECT ']]]]]]]]ABC[DEF'
)
SELECT PATINDEX('%[^' + char(7) + ']%', REPLACE(Value,']', char(7)))
FROM T
(Returns 9)

RowFilter including [ character in search string

I fill a DataSet and allow the user to enter a search string. Instead of hitting the database again, I set the RowFilter to display the selected data. When the user enters a square bracket ( "[" ) I get an error "Error in Like Operator". I know there is a list of characters that need prefixed with "\" when they are used in a field name, but how do I prevent RowFilter from interpreting "[" as the beginning of a column name?
Note: I am using a dataset from SQL Server.
So, you are trying to filter using the LIKE clause, where you want the "[" or "]" characters to be interpreted as text to be searched ?
From Visual Studio help on the DataColumn.Expression Property :
"If a bracket is in the clause, the bracket characters should be escaped in brackets (for example [[] or []])."
So, you could use code like this :
DataTable dt = new DataTable("t1");
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Description", typeof(string));
dt.Rows.Add(new object[] { 1, "pie"});
dt.Rows.Add(new object[] { 2, "cake [mud]" });
string part = "[mud]";
part = part.Replace("[", "\x01");
part = part.Replace("]", "[]]");
part = part.Replace("\x01", "[[]");
string filter = "Description LIKE '*" + part + "*'";
DataView dv = new DataView(dt, filter, null, DataViewRowState.CurrentRows);
MessageBox.Show("Num Rows selected : " + dv.Count.ToString());
Note that a HACK is used. The character \x01 (which I'm assuming won't be in the "part" variable initially), is used to temporarily replace left brackets. After the right brackets are escaped, the temporary "\x01" characters are replaced with the required escape sequence for the left bracket.