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 need a simple solution for the problem in C#
Input : Any Body Can Dance
Output : ABCD
string inputString = "Another One Bites The Dust And Another One Down";
string[] split = inputString.Split();
foreach (string s in split)
{
Console.Write(s.Substring(0,1));
}
Check this out:
string s = new string("Any Body Can Dance"
.Split(' ')
.Select(x => x.First())
.ToArray());
Console.WriteLine(s);
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.
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.
The input string: A+SUM(A)C+AB-C+SUM(A)+1
I want to replace A with 0, the result like this:0+SUM(A)C+AB-C+SUM(A)+1
or replace SUM(A) with 0, the result like this:A+SUM(A)C+AB-C+0+1
Thanks
Without Regex (because Regex is overkill for this):
var s = "A+SUM(A)+B-C";
var replaceBeginningA = s.Replace("A+", "0+");
var replaceSumA = s.Replace("SUM(A)", "0");
Console.WriteLine(replaceBeginningA); // 0+SUM(A)+B-C
Console.WriteLine(replaceSumA); // A+0+B-C
As pointed out in the comments though, you need to provide more detail if this input is expected to have a different format.
maybe:
replace ^A with 0
replace SUM\(A\) with 0
Try thus:
string replaced = Regex.Replace(input, #"\b(\w+)\+SUM\(\1\)", "0+0");
This will match anything of the form
foo+SUM(foo)
and replace it with 0+0
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.
How to replace between two characters in a string based on their Unicode code point ?? Could any help please ??Many Thanks.
For example,
Replace (U0041 with U0066)
Use the \u escape code to write the characters:
str = str.Replace('\u0041', '\u0066');
Alternatively, convert the numbers into characters:
int char1 = 65;
int char2 = 102;
str = str.Replace((char)char1, (char)char2);
You can do it like this:
Console.WriteLine("ABC".Replace("\u0041", "\u0066"));
This produces the output fBC, because the unicode code point of u0041 (which is A) has been replaced with the code point of u0066 - an f.
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 10 years ago.
Continuing from my previous question, I now want to remove the number once I have found it and stored it in a variable.
Just a slight tweak to my response to your first question to instead use Regex.Replace method will git 'er done.
Don't worry I figured it out. Just need to find the length then delete the chars
(qual is the intergers found)
string length = qual.ToString();
int length2 = length.Length;
text.Remove(0, length2);
I think the following code resolves the root problem:
string originalString = "35|http://www.google.com|123";
string[] elements = originalString.Split(new char[] { '|' }, 2);
int theNumber = int.Parse(elements[0]); // 35
string theUrl = elements[1]; // http://www.google.com|123