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 7 years ago.
Improve this question
Example Word : String , the returned last index is 5 which is "g". I need to complete the word string base on the space before the word.
For example
obj string the last index is 5, which is g, "string" word should be completed.
If you are using C#, you can use String.LastIndexOf method to report the last occurrence of ' ' character then use String.Substring to extract the word.
For other languages, Google is your friend :)
Related
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 1 year ago.
Improve this question
I have a string that I want to remove some characters from
I want all % symbols and the character directly following that character to be removed
e.g. Apple%j pie turns into Apple pie
I want it to do this several times too, so Chicken%f and%f waffles turns into Chicken and waffles
Use regex matching a percent sign then any character:
var result = Regex.Replace("Chicken%f and%f waffles", #"%.", "");
//Chicken and waffles
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 4 years ago.
Improve this question
My String: draw.text("hello",11,22);
Need Output: 11
So i need to get a String Between first , character and Last , character.
Its not duplicate question.I not found same questions.
I need to get the 2nd argument in my string,the string between first , and last , in string
Split your string on the , character, remove the first and last item, and join the remaining components back together:
var input = "draw.text(\"hello\",11,22);";
var components = input.Split(',');
var result = String.Join(",", components.Skip(1).Take(components.Length - 2));
// yields 11
Note: using System.Linq is required for Skip and Take.
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 5 years ago.
Improve this question
What is the regex for matching a date starting at the 4th position? I want it to return just the date and not the whole match. This is what I have.
^.{4}[2-9][0-9]{3}[0-1][0-9][0-9]{2}
DCSG20170406090204-FQI-046.TOT 04-FIC-046 00060Y000815050.562500G
DCS120170406090204-FQI-045.TOT 04-FIC-045 00060Y000878279.312500G
DCS120170406090204-FQI-046.TOT 04-FIC-046 00060Y000815050.562500G
http://regexr.com/3g0d5
You probably want a non-capturing group:
^(?:.{4})([2-9][0-9]{3}[0-1][0-9][0-9]{2})(?:.*)$
(mouse over the text at: http://regexr.com/3g0db and it will show just one group)
I don't know C#, but from my Perl perspective, I don't see any need for a regular expression. If you just want "the date" and don't need to validate it or separate it into components, just get the substring starting at position 4 (0 based) and 8 characters long.
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);
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
I need one white space only in my regular expressen.
How should I create the code that validate if one white space is availabe in the string value?
I'm not sure exactly what you mean but I'm guessing you want to check for exactly one whitespace, but any number of non-whitespace characters:
#"^\S*\s\S*$"
Example code:
Regex regex = new Regex(#"^\S*\s\S*$");
Console.WriteLine(regex.IsMatch("Hello, world!"));
Console.WriteLine(regex.IsMatch("This contains three spaces."));
Console.WriteLine(regex.IsMatch("Two\nlines."));
Output:
True
False
True
Other variations
To check if the string contains exactly one whitespace only (no other characters):
#"^\s$"
To check if the string contains at least one whitespace:
#"\s"