Delete duplicate multiple lines using vscode - visual-studio-code

i have so many line just like this json code (120000 lines)
{
"name":"V83.9",
"name":"Work",
"name":"V83.9",
"name":"Education",
"name":"V83.9",
"name":"Profession"
}
and i want this convert just like this
{
"name":"V83.9",
"name":"Work",
"name":"Education",
"name":"Profession"
}
and i wrote regex on vscode just like this but this is not working
Find: {\n"name":"$1",\n"name":"$2",\n"name":"$1",\n"name":"$3",\n"name":"$1",\n"name":"$4"\n}
Replace: {\n"name":"$1",\n"name":"$2",\n"name":"$3",\n"name":"$4"\n}
How do i do this?

Please check the Transformer extension, where i have applied it on your example and it works:

Related

Scala how to use regex on endsWith?

I'm trying to figure out how to isolate all file extensions from a list of file names using regex and endsWith.
So as an example
input:
file.txt, notepad.exe
output:
txt, exe
What my idea is, is to use filter to get file names that endsWith("."_). But endsWith("."_) doesn't work.
Any suggestions?
You really do not want to filter, you want to map each filename into its extension.
(and maybe then collect only the ones that had an extension and probably you only want each unique extension)
You can use a regex for that.
object ExtExtractor {
val ExtRegex = """.*\.(\w+)?""".r
def apply(data: List[String]): Set[String] =
data.iterator.collect {
case ExtRegex(ext) => ext.toLowerCase
}.toSet
}
You can see it running here.
how about using split('.') which will return a
String[] parts = fileName.split("\\.");
String extension = parts[parts.length-1];

Scala replace one text for another text with special chars included

i need a function to replace one text per another one, currently this is the code i am using, but it's not really working, or at least instead of replacing, removing the text and leave it empty, this is the code:
Thanks for your time, appreciated
def replaceIcons(message: String) = {
message.replaceAll("[|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]:", "[https://cdn.discordapp.com/emojis/511683443231424532.png?v=1]:")
}
This is the message i want to replace i.postimg.cc/zDHwfXHX/ser.png
The expected output is this one: i.postimg.cc/k4mCt5X3/serr.png
Example message to replace:
[global] [Zerobalas]: [|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]: asd
Example output expected:
[global] [Zerobalas]: [https://cdn.discordapp.com/emojis/511683443231424532.png?v=1]: asd
Try this:
def replaceIcons(message: String) = {
message.replace("[|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]:", "[https://cdn.discordapp.com/emojis/511683443231424532.png?v=1]:")
}
println(replaceIcons("[global] [Zerobalas]: [|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]: asd"))

How to select symbols onWorkspaceSymbol

I am developing an extension for visual studio code using language server protocol, and I am including the support for "Go to symbol in workspace". My problem is that I don't know how to select the matches...
Actually I use this function I wrote:
function IsInside(word1, word2)
{
var ret = "";
var i1 = 0;
var lenMatch =0, maxLenMatch = 0, minLenMatch = word1.length;
for(var i2=0;i2<word2.length;i2++)
{
if(word1[i1]==word2[i2])
{
lenMatch++;
if(lenMatch>maxLenMatch) maxLenMatch = lenMatch;
ret+=word1[i1];
i1++;
if(i1==word1.length)
{
if(lenMatch<minLenMatch) minLenMatch = lenMatch;
// Trying to filter like VSCode does.
return maxLenMatch>=word1.length/2 && minLenMatch>=2? ret : undefined;
}
} else
{
ret+="Z";
if(lenMatch>0 && lenMatch<minLenMatch)
minLenMatch = lenMatch;
lenMatch=0;
}
}
return undefined;
}
That return the sortText if the word1 is inside the word2, undefined otherwise. My problem are cases like this:
My algorithm see that 'aller' is inside CallServer, but the interface does not mark it like expected.
There is a library or something that I must use for this? the code of VSCode is big and complex and I don't know where start looking for this information...
VSCode's API docs for provideWorkspaceSymbols() provide the following guidance (which I don't think your example violates):
The query-parameter should be interpreted in a relaxed way as the editor will apply its own highlighting and scoring on the results. A good rule of thumb is to match case-insensitive and to simply check that the characters of query appear in their order in a candidate symbol. Don't use prefix, substring, or similar strict matching.
These docs were added in response to this discussion, where somebody had very much the same issue as you.
Having a brief look at VSCode sources, internally it seems to use filters.matchFuzzy2() for the highlighting (see here and here). I don't think it's exposed in the API, so you would probably have to copy it if you wanted the behavior to match exactly.

Codemirror get all lines as array

Is there a way in Codemirror to get all the lines in the editor, represented as an array? I know it is possible to iterate over each lines like so..
editor.eachLine(line => {
// do something with line
})
..but I'm looking for a way to just get all the lines, something like editor.allLines() or something..
With editor.getValue(separator) you can get all lines as a sting separated by the given separator - default is "\n".
Then you can turn your previously generated string into an array with string.split(separator)
function getAllLinesAsArray (codeMirror) {
return codeMirror.getValue().split('\n')
}
DEMO: https://codepen.io/quic5/pen/WLzJPx

Cannot iterate through Shapes collection

C# and word interop,
I have a word document with some textboxs (msoTextBox shapes), the problem that I can't iterate through the shapes collection with the code below :
foreach (Shape shape in WordDocument.Shapes)
{}
although when setting a breakpoint in the loop line I can see that WordDocument.Shapes.Count returns 4.
I note that textboxs are inserted using open xml sdk.
I've found there's a problem when textboxes are used. Take a look at this solution.
From Code Project :
// Get the word count from all shapes
foreach (Word.Shape shape in wordDocument.Shapes)
{
if (shape.TextFrame.HasText < 0)
{
count+=GetCountFromRange(shape.TextFrame.TextRange,wordDocument,word);
}
}
From what you said, you look like you do the right thing.
Can you give us the Error StackTrace ?
PS : I know my question should have been in the comments, but it wouldn't have been readable :)
So,
Replace :
foreach (Shape shape in WordDocument.Shapes)
{
}
By:
foreach (Range rangeStory in WordDocument.StoryRanges)
{
foreach (Shape shape in rangeStory.ShapeRange)
{
}
}
It's work perfectly.