How do I add text into my string? [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I though it was simple. but I didn't manage to make this line of code add "\Game_Progress.xml" to my String
code_file.Insert(code_file.Length, "\\Game_Progress.xml");

You can append the string using the += operator:
code_file += "\\Game_Progress.xml";
Note: If you want to combine a path, you should consider using the Path Combine method:
System.IO.Path.Combine(code_file, "\\Game_Progress.xml")

C# can require an #prior to the string when using backslashes. Try:
code_file.Insert(code_file.Length, #"\\Game_Progress.xml");

Related

How i can get the first match in regex and import this match in a string? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
For example using a regex expression del(.*?)del get delcatdel
and save the result in string or in text
word1word2delcatdelword3word4deldogdelword5
in my text (or string) i need obtain delcatdel
USING c sharp
please anybody help me
var regex = new Regex("del(.*?)del");
var match = regex.Match("word1word2delcatdelword3word4deldogdelword5");
string matched = match.Value;

Custom regular expression for string with number [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have to validate a sting with regular expression.
String Should be in the NHCC-XXXXX-00 Format ,where X is a Number.
Correct strings:
NHCC-10010-00,
NHCC-78965-00,
NHCC-99654-00
Wrong strings:
NHCC-1001-00
NHCC-78965-0
NHC-99654-00
ASDF-99654-00
NHCC-F9654-00
NHCC-99654-01
Can any one help me to solve the above senario?
This should work:
"NHCC-\d{5}-00"
Demo
You need to use anchors inorder to do an exact match.
#"^NHCC-\d{5}-00$"
The regular expression you want is #"(?s)^NHCC-\d{5}-00$"
if (!Regex.IsMatch(input, #"(?s)^NHCC-\d{5}-00$"))
{
//not valid
}

C# Regex questions [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How can I extract the word "Word" (or any word) using Regex into a string in both cases? in the following string:
Word = CreateObject(980, -1696.5996, -12.2998, 5.3, 0, 0, 317.999);
MoveObject(Word, -1660.9004, 79.40039, 2.2,6);
I am pretty new in Regex, and I am having hard time understanding the tutorials over the internet.
I have tried using /(.*)( = CreateObject)/ but no luck
Tried using /MoveObject\(.*?\,/ and it works, but it matches MoveObject too, and I want it to match only "Word"
Thanks!
You could try the below regex.
#".*?(?= = CreateObject)|(?<=MoveObject\().*?(?=,)"
OR
#"\S+?(?= = CreateObject)|(?<=MoveObject\().*?(?=,)"
DEMO

how to remove particumar letter combination from a string in c#? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a string like below
he/a0h/a0dv/a0jks
I would like to be string become as below.
hehdvjks
Need to remove the "/a0" from the string.
The String.Replace method is what you're looking for, just do a;
String myString = "he/a0h/a0dv/a0jks"
myString = myString.Replace("/a0", "")
It'll return a modified 'myString' with all occurrences of the old value ("/a0") replaced with a new value (blank in this case).
The MSDN reference for String.Replace can be found at:
http://msdn.microsoft.com/en-us/library/fk49wtc1%28v=vs.110%29.aspx
var result = "he/a0h/a0dv/a0jks".Replace("/a0", string.Empty);

How can I get the contents of a string before a particular character? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to get the previous chars from a certain char in a string.
For example: myString = "26+", so I want to get 26 without +. How can I do this?
Use Substring and IndexOf.
string str = "26+";
string requiredString = str.Substring(0, str.IndexOf('+'));
strings are immutable in C# and you have to assign the results to string itself or some other string.
The function String.Substring will do what you need.
yourString.Substring(0, keepCharactersBeforeHere);

Categories