Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search a word only in string literal in visual studio?

I need to find all occurrences of a word that are part of a string literal in my c# solution. So I want to restrict my search to words in quoted sequences of characters.

For instance if I search for the word magic, the following line should not appear in the result :

string magic = "hello dad" 

,and conversely, the following line should be found:

string test = "this is a magic line"

Can you help me with this ?

like image 444
Malick Avatar asked May 30 '18 22:05

Malick


People also ask

How do I search for a string in Visual Studio?

Ctrl + Shift + F – Find in Solution Sometimes you want to search across your entire solution. You can double-click each item in the “Find Results” window to navigate to that instance of the search term you searched for.

How do I find a specific word in a string C#?

In C#, IndexOf() method is a string method. This method is used to find the zero-based index of the first occurrence of a specified character or string within the current instance of the string. The method returns -1 if the character or string is not found.

How do you recognize a string literal?

A "string literal" is a sequence of characters from the source character set enclosed in double quotation marks (" "). String literals are used to represent a sequence of characters which, taken together, form a null-terminated string. You must always prefix wide-string literals with the letter L.

What is a string literal in C#?

String literals or constants are enclosed in double quotes "" or with @"". A string contains characters that are similar to character literals: plain characters, escape sequences, and universal characters. You can break a long line into multiple lines using string literals and separating the parts using whitespaces.

How do I search within a string in Visual Basic?

This article shows an example of how to search within a string in Visual Basic. This example calls the IndexOf method on a String object to report the index of the first occurrence of a substring: The IndexOf method returns the location of the first character of the first occurrence of the substring.

How do I search for text in a string?

You can use two main strategies to search for text in strings. Methods of the String class search for specific text. Regular expressions search for patterns in text. The C# examples in this article run in the Try.NET inline code runner and playground.

What are strings in Visual Basic?

This topic introduces the basic concepts of strings in Visual Basic. String Variables An instance of a string can be assigned a literal value that represents a series of characters. For example: Dim MyString As String MyString = "This is an example of the String data type" A Stringvariable can also accept any expression that evaluates to a string.

How do I assign a literal value to a string?

An instance of a string can be assigned a literal value that represents a series of characters. For example: Dim MyString As String MyString = "This is an example of the String data type"


1 Answers

Just moving this from comments to answer.

CTRL + SHIFT + F > Uncheck "Match Case" > Check "Match Whole Word" > Check "Use Regular Expressions" > Enter the following in Find what: ".*magic.*" (include the quotes)

like image 98
Ingenioushax Avatar answered Sep 19 '22 00:09

Ingenioushax