It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm trying to put this string in my resources:
Environment.CurrentDirectory + \\Server Files\\
But whenever I load the string, the Environment.CurrentDirectory part is shown as normal text instead of the current directory path :(.
Example:
Console.WriteLine(Resources.ServerFilesLocation); // Doesn't give me a path, but just plain text.
Any runtime environment value cannot be stored as a string in resources. What you should do is create a layer between. Something like:
static class ResourceManager
{
public static string ServerFilesLocation {
get {
return String.Format(Resources.ServerFilesDirectory, Environment.CurrentDirectory);
// ServerFilesDirectory = "{0}\\Server Files\\" or something similar
}
}
}
And use it like: Console.WriteLine(ResourceManager.ServerFilesLocation);
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a string variable which has the value that the user taps. I need to make another variable which its name will be the string's value.
How do / can I do that?
No, you cannot do that: the closest you can get is a Dictionary<string,object> (you can replace the object with some other type). Using this dictionary you would be able to create associations between strings (known as "keys") and values stored in the dictionary.
IDictionary<string,object> variables = new Dictionary<string,object>();
string varName = "hello";
variables[varName] = "world";
Console.WriteLine("Name: {0} Value: {1}", varName, variables[varName]);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How can I do the following in C# :
var re = /^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$/;
re.test('2013/03/05 15:22:00'); // returns true
You can use the Regex.IsMatch instead (docs).
Regex.IsMatch("2013/03/05 15:22:00", #"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$"); // true if match
The below code should get you where you want to be.
Regex rx = new Regex(#"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$");
String test = "2013/03/05 15:22:00";
if (rx.IsMatch(test))
{
//Test String matches
}
else
{
//Test String does not match
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have an array of words and I want to remove them from an input string, could anyone tell me what is the better way to conduct this task?
This should work
string[] arrToCheck = new string[] { "try ", "yourself", "before " };
string input = "Did you try this yourself before asking";
foreach (string word in arrToCheck )
{
input = input.Replace(word, "");
}
MessageBox.Show("result is "+input);
input variable will now have a string which does not have those words in your array.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have
C:\Softwares\Test\ASPnetTest\Project11\Shared\Public\Images\
How to convert it to
Shared\Public\Images\
Thank you.
If you want the path as used in a URL:
You can use something like this (classes are valid in C# too): http://geekswithblogs.net/AlsLog/archive/2006/08/03/87032.aspx
Public Function MapURL(ByVal Path As String) As String
Dim AppPath As String = _
HttpContext.Current.Server.MapPath("~")
Dim url As String = String.Format("~{0}" _
, Path.Replace(AppPath, "").Replace("\", "/"))
Return url
End Function
...To make it easy:
private static string MapUrl(string path)
{
var appPath = HttpContext.Current.Server.MapPath("~");
return string.Format("~{0}", path.Replace(appPath, "").Replace("\\", "/"));
}
If you want the folder, relative to your app's base path:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.physicalapplicationpath.aspx
Request.PhysicalApplicationPath will give you the c:\softwares\test\aspnettest\project11 part. Then you can get the relative part, see this answer here for that:
How to get relative path from absolute path
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I'm working on something like recycle bin, that I need to move folder/files to already existing folder, I tried to use
Directory.Move
but it creates new directory and that's wrong for me, I have a specific directory to move to.
Can you help me?
It seems do don't actually want to move the folder, you want to move the contents of the folder. If you want to do that, you have to tell the computer to do that:
void MoveContentsOfDirectory(string source, string target)
{
foreach (var file in Directory.EnumerateFiles(source))
{
var dest = Path.Combine(target, Path.GetFileName(file));
File.Move(file, dest);
}
foreach (var dir in Directory.EnumerateDirectories(source))
{
var dest = Path.Combine(target, Path.GetFileName(dir));
Directory.Move(dir, dest);
}
// optional
Directory.Delete(source);
}