How do I find strings to be localized in my C# project? - c#

I'm trying to write a regex to be used within Visual Studio or an external program without success. What I want that expression to do is:
Match rows containing quoted text like var myString = "This shall be moved out of here"
Do not match rows within comments like ///<summary>This method has some "quoted text"</summary> or //This is "just a comment", which may have tabs at their beginning due to indentation.
From within Visual Studio I'm able to include files by extension, say *.cs, so I can easily skip xml files and so on. I'm not able to exclude those *.Designer.cs files however, so I found that FileSeek does a pretty good job being able to include and exclude files by extension or regex; anyway if there's a way to accomplish the same from VS, that would be great.
Any help would be much appreciated, thank you.

The below regex would match all the lines that won't start with // and contains " present inside that.
^(?!\s*\/\/).*(?=\").*$
DEMO

Related

is there rules for comments in editorconfig file

I did a custom .editorconfig file which I apllied the nameing conventions like(interfaces should begins with I and then Uppercase) and works just fine (except the fact that it doesnt fix the names automatically after i run code cleanup). and i was wondering if there were a set of rules to control the comments, for example, the line should starts with space then the comments, and it should start new line after 100 character.
I dont want to use third party softwares, I would like to use vanilla visual studio

Is there any Visual Studio Extension that removes the resource strings and replace it with actual strings values that was part of resource?

As title suggest, I am looking for a Visual Studio Extension that lets me remove some of the strings that are in the resources file back in to where it belongs in the code.
I desire this because someone in our projects tossed in the strings that are in the code that deals with xml nodes or paths.
Because we use all the strings that are in resource file as strings to localize, having strings that are desired to be translated in there causes disaster.
Thanks in advance.
You can use ReSharper
It has the feature "Inline Resource" which "deletes a resource entry from a resource file and substitutes all its usages with the original string."

Significance of a PATH explained

This is probably a rudimentary question but I am still kinda new to programming and I've wondered for awhile. I've done multiple projects in Python, C#, and Java, and when I try to use new libraries (especially for Python) people always say to make sure its in the right PATH and such. I just followed an online tutorial on how to install Java on a new computer and it rekindled my question of what a path really is. Is the Path just were the programming language looks for a library in the file system? I get kinda confused on what it's significance is. Again, I'm sorry for the wide question, its just something that I've never quite gotten on my own programming.
EDIT: I just wanted to thank everyone so much for answering my question. I know it was a pretty dumb one now that I've finally figured out what it is, but it really helped me. I'm slowly working through as many C#, Java and Python tutorials as I can find online, and it's nice to know I have somewhere to ask questions :)
The PATH is an environment variable which the shell (or other command interpreter) uses to search for commands. Usually (always?) commands are found with a greedy algorithm, so entries that come first in the PATH are returned first. For example, a command in /usr/local/bin will override a command in /usr/bin given a PATH such as
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
while the purpose is consistent, the syntax is slightly different on WINDOWS - you would use
C:\> ECHO %PATH%
to "echo" your PATH.
First my shell is going to search /usr/local/sbin then /usr/local/bin then /usr/sbin and then /usr/bin before searching /sbin and /bin if the command isn't found then it will report that it couldn't find such a command...
# Like so
$ thisprogramdoesntexist
thisprogramdoesntexist: command not found
Now, on Linux at least, there's also a LD_LIBRARY_PATH which the system will use to search for dynamic libraries (greedily), on Windows I think it just uses the PATH. Finally, Java uses a CLASSPATH which is similar (but used to search for classes and JARs).
On Linux one might add an entry to the PATH like so,
$ export PATH="$PATH:/addNewFolder"
While on Windows you might use
set PATH=%PATH%;c:\addNewFolder
Sometimes, you might manipulate your PATH(s) to enable specific functionality, see update-java-alternatives on Ubuntu for an example.
A PATH is a file directory on your computer. If you need to install a programming language, you might need to put it in your system PATH variable. This means that the system looks to these files for different information, IE where the libraries for the code you are using are.
Hope that helped!
Exactly as other said, PATH is a list of folders that is included in the search -other than the current folder- and you can always access straight away. It's one of the Environment Variables.
For example, we have the python folder in C:\Python27. I'm sure you know that to run a python file, we commonly use python script.py.
What happens is that the command line searches for python.exe in your current folder, and if not found, search it in the folders in the path variable.
To read the path, you can, straightforwardly use:
$ PATH
If you're on windows, like i am, an easy way to deal with this is to just use System Properties. Just type it in the start menu, open it, and go to the 'advanced' tab. Click on the Environment Variables, there! You'll see a PATH variable, and you can modify it as you want.
I myself use more than one version of Python, and to deal with this, i appended all the folders to PATH, and changed my python.exe to pythonversion_number.exe. Problem solved! Now, i can run this in the command line:
$ python26 script.py
$ python33 script2.py
Some further reading on this, if you're interested, here's a good question asked
Hope this helps!
The best resource (so far) about PATH information, you can see in this question:
https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them
Stack Overflow is not the best place to search about this, always check the amazing
https://superuser.com/ for this kind of question.
PATH is a symbolic name usually associated to string values separated by a semicolons (where each string part is a directory name). This symbolic name (and its values) is handled by the operating system and could be modified by the end user through the some command line instruction like SET PATH=........ or through some kind of user interface configuration tool.
It is common practice for tools like compilers or other programming tools to look at this symbolic name and use the list of string values for searching files that are not directly available in the current folder used by the tools.
So, if an installation procedure set the PATH symbol in this way
SET PATH=%path%;C:\PROGRAM FILES\MYTOOLFOLDER;
it means, set the PATH symbol to the previous value (%PATH%) and add another string value to it (C:\PROGRAM FILES\MYTOOLFOLDER).
Then the tool, when it needs to search for a particular file or library, could read the PATH symbol values, split them at the semicolons and iteratively look at the directories listed one by one looking for the file required.
In C# programming, for example, the tool code could contain something like this
string pathSymbol = Environment.GetEnvironmentVariable("PATH");
string[] pathFolders = pathSymbol.Split(';');
foreach(string folder in pathFolders)
{
if(File.Exists(Path.Combine(folder, "mylibrary.dll"))
{
..... do whatever you need to do with the file
}
}
This example assumes a Windows environment.

Crashed when adding a really long line of code

I am using VS 2010 express for C#.
I am making a random chinese name generator.
I have nearly 200 thousands first name to be drawn.
When I add a really long code with these first names like
string[] firstname = new string[] {"A","B",...}
VS was in heavy load when I opened the project or attempted to click on the line. Actually, after adding the line, I cant even open the project.
I guess it is due to the auto-debugging function as it is not so laggy when I try to edit in notepad++.
Any recommendation on handling the problem of drawing a large set of elements?
Or how can I stop the auto-debugging function?
string[] firstname =
System.IO.File.ReadAllLines("list-of-names-one-per-line.txt");
You should really consider reading from some kind of storage. This will also allow you to change the word list without recompiling your program.
If you must, Tools->Options->Text Editor->C#->Advanced uncheck Show live semantic errors
Read the values from a file. If you want to ensure the contents are included with an executable, then embed the file as a resource in the project and read the contents from there.

Visual studio autocomplete to find a file?

In the Visual Studio, do we have a tool to find a file based on file name insdie a project, like typing a few letters of beginging of a file, it will autocomplete to show all files starting with that letters. In the Java Eclipse, we can use Ctrl+Shift+R , do we have similar in the VS ?
Thanks
Yes, there is something like that.
You can use the Find text box you use for normal searches as input for the Command Window. Then in the Command Window you have the of command to search files.
To do it:
CTRL + /to select the Find text box.
Type > of then the file name (or part of) you want to search for.
A dropdown list will show all files that match your typing (so you do not have to know the full file name as with CTRL + SHIFT + R).
If file list is pretty long you may use the normal Find in Files dialog, simply set Use to Wildcards, in Find what type * and write the search pattern in Look at these file types. Check the Display file name only option. Using the Look in field you can limit the search to current project, entire solution or whatever you need.
Try ctrl-spacebar, it's the normal shortcut for intelisense. If it doesn't work for file path and name, there is surely a plugin out there just for this.
I use VS with only resharper as a plugin and I can do this, I don't know if its resharper that does it or if its prebuilt.
EDIT: It is resharper that does it. I would recommend using it if you intent to work with VS as it greatly helps out on a lot of refactoring and shortcuts.

Categories