Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I need to find and replace all "B1:1" in string "A4:1_A1:1_A2:1_A3:2_A4:1_B1:1_B2:2200_"
on "B1:880".
Newbie in regex and need some help with it and Regex.Replace()
<YourString>.Replace("B1:1", "B1:880"); should do it too, right?
In case of multiple occurrences
Regex.Replace( "Your String", #"^B1:1$","B1:880" );
You could use String.Split with a little bit LINQ:
str = string.Join("_", str.Split('_')
.Select(s => s == "B1:1" ? "B1:880" : s));
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 months ago.
Improve this question
How effectively remove all character in string that placed before character "\"?
Input: C:\Users\vadym\OneDrive\Робочий стіл\sharp-kn3-lab2-2022-autoteam\AutoOA\AutoOA.UI\wwwroot\Images\room.png
Output: \Images\room.png
One way to do this without having to perform manual manipulation of the path is by relying on Directory and Path classes.
Note that this doesn't include some error conditions and corner cases that you might want to double check for:
var input = #"C:\Users\vadym\OneDrive\Робочий стіл\sharp-kn3-lab2-2022-autoteam\AutoOA\AutoOA.UI\wwwroot\Images\room.png";
var parentDirectory = Directory.GetParent(input).Parent.FullName;
var relativePath = Path.GetRelativePath(parentDirectory, input);
Console.WriteLine($"Input: {input}");
Console.WriteLine($"Directory: {parentDirectory}");
Console.WriteLine($"Relative path: {relativePath}");
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 am trying to concat a variable to a regen in c# but it is not working
string color_id = "sdsdssd";
Match variations = Regex.Match (data, #""+color_id+"_[^\""]*\""\W\,\""sizes\""\:\s*\W.*?businessCatalogItemId"":\"")", RegexOptions.IgnoreCase);#""+color_id+"_[^\""]*\""\W\,\""sizes\""\:\s*\W.*?businessCatalogItemId"":\"")";
But the above is not working
How to concat a variable at starting element to regex in c#
The # identifier only affects the immediately following literal string - you need to apply it to each string that needs it:
Match variations = Regex.Match (data,color_id +
#"_[^\""]*\""\W\,\""sizes\""\:\s*\W.*?businessCatalogItemId"":\"")",
RegexOptions.IgnoreCase);
Your code is not working because you appear to have put this into your code twice.
#""+color_id+"_[^\""]\""\W\,\""sizes\"":\s\W.*?businessCatalogItemId"":\"")"
Removing that should allow the concatenation to work.
Alternatively, you could use String.Format to make the pattern
string pattern = String.Format("#{0}_[^\""]*\""\W\,\""sizes\""\:\s*\W.*?businessCatalogItemId"":\"")", color_id)
Match variations = Regex.Match (data, pattern, RegexOptions.IgnoreCase);
In the String.Format, it will replace the {0} with color_id. You can use this to insert multiple variable into the string. Take a look at this MSDN page for more info
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);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am sorry for that bad Title, but basicaly my problem is really simple. I got 1 string which is basic alphabet and the second string which is gonna be part of the alphabet (8 characters) which user will fill up by himself. If 2 characters are the same, they will get removed and then rest of characters will be in the TextBox3. could someone pls help me ?
string alphabet = "abcdefghijklmnopqrstuvwxyz_*";
string special = TextBox2.Text;
I assume you want to check the existence of substring and remove from the parent string, Try this
string alphabet = "abcdefghijklmnopqrstuvwxyz_*";
string special = textBox2.Text;
if (alphabet.ToLowerInvariant().Contains(special))
{
textBox3.Text = alphabet.Replace(special, "");
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want regx pattern in C# which find substring in any string which comes in middle only. Let say ,
Input : "toprohitpop rohittoppop toppoprohit"
find substring : "rohit"
Replace with : "$$$$"
Output : "top$$$$pop rohittoppop toppoprohit"
if substring "rohit" comes in left or right of the string then it should not be replaced.Substring "rohit" will only be replaced when it comes in middle of string .
Thanks in advance.
Use non-word-break anchors:
\Brohit\B
The \B will only match if it is in the middle of a word.
Read about it.
var input = "toprohitpop rohittoppop toppoprohit";
var regex = new Regex(#"\Brohit\B");
var output = regex.Replace(input, "$$$$$$$$");
See "Anchors" in Regular Expression Language.
Also, be careful with the '$' in the substitution string (see comments)
Use the following regex: .+rohit.+
Basically it enforeces at least one char before rohit and one after