Hello All,
I am new to C# kindly help me with the Expected output:
What i have Done...
string strCombination = "((B48B20, XB1141) + PLUGIN_HYBRID + ECE), (B57D30 + TL + ECE), (B58B30 + ML + KEIN_HYBRID + ECE), (B57D30 + SL + US)";
string strCombination_Pattern = @"\((.*?)\)";
Regex rgx1 = new Regex(strCombination_Pattern, RegexOptions.IgnoreCase);
MatchCollection matches1 = rgx1.Matches(strCombination);
if (matches1.Count > 0)
{
foreach (Match match in matches1)
{
Regex rgx1 = new Regex(strCombination_Pattern, RegexOptions.IgnoreCase);
MatchCollection matches1 = rgx1.Matches(strCombination);
if (matches1.Count > 0)
{
foreach (Match match in matches1)
{
Console.WriteLine(match.Value);
}
}
}
Output:
match.Value = (B48B20, XB1141) ,(B57D30 + TL + ECE),(B58B30 + ML + KEIN_HYBRID + ECE),(B57D30 + SL + US)
Expected output:
(B48B20, XB1141)+ PLUGIN_HYBRID + ECE ,(B57D30 + TL + ECE),(B58B30 + ML + KEIN_HYBRID + ECE),(B57D30 + SL + US)
Thank u
Sampath
VulpesPosted Feb 19, 2014, 7:15 AM
The output is:
VulpesPosted Feb 27, 2014, 9:31 AM
However, the regular expression is only designed to remove excess leading or trailing parentheses from an expression of the form: ((a)b)
It won't work generally and it's probably impossible to come up with a single regular expression which will. It's really a job for a parser.
sampath mekaPosted Feb 27, 2014, 3:23 AM
VulpesPosted Feb 21, 2014, 6:07 AM
"(?:[^a-z0-9 _]|(?<=['\"])s)"
sampath mekaPosted Feb 21, 2014, 4:47 AM
Thanks u
sampath mekaPosted Feb 21, 2014, 3:54 AM
i have one doubt that is i am using one expression for remove of all special characters,but i want to exclude _(underscore)from the string.
Regex r = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
return r.Replace(input, String.Empty);
For Example:
string str_Remove = "((PLUGIN_HYBRID))";
Regex r = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
return r.Replace(str_Remove , String.Empty);
Expected Output:
PLUGIN_HYBRID
My output using the above expression is
PLUGINHYBRID
Using the above expression how can i exclude _(underscore)from the string.
Thanks for helping me a lot.....
VulpesPosted Feb 20, 2014, 12:20 PM
The output is:
VulpesPosted Feb 20, 2014, 10:18 AM
The output is:
However, it's impossible to extend this to deal with strCombination2 as well because:
1. Unlike the other two expressions, the split you want removes characters other than the separators from the original expression. Regex.Split never does this.
2. The split you want is based on commas within brackets whereas the first expression deliberately ignored commas embedded in brackets i.e. the sub-expression ((B48B20, XB1141) wasn't split.
sampath mekaPosted Feb 20, 2014, 12:38 AM
Thanks for u reply,i have two more string as follows...
string strcombination1 = "5AT_DRIVING_ASSISTANT_PLUS, 5AU_DRIVING_ASSISTANT_PREMIUM_ARBEITSNAME, 5DP_PARKASSISTENT, 5DV_PARKASSISTENT_PLUS_ARBEITSNAME";
Expected output:
5AT_DRIVING_ASSISTANT_PLUS
5AU_DRIVING_ASSISTANT_PREMIUM_ARBEITSNAME
5DP_PARKASSISTENT
5DV_PARKASSISTENT_PLUS_ARBEITSNAME
string strcombination2 = "~alle_Anderen~ !((BENZIN, BATTERIE_BENZIN), (DIESEL))";
Expected output:
BENZIN
BATTERIE_BENZIN
DIESEL
previously u have reply me for question
string strcombination ="((B48B20, XB1141) + PLUGIN_HYBRID + ECE), (B57D30 + TL + ECE), (B58B30 + ML + KEIN_HYBRID + ECE), (B57D30 + SL + US)";
Answer is :
//Working for strcombination
foreach (string s in Regex.Split(strCombination, @"(?<=\)), "))
{
Console.WriteLine(s);
}
//working for strcombination
but i need the expression which should work for all strcombination,strcombination1 and strcombination2,kindly help me i will be very much thankful to u ...
sampath mekaPosted Feb 19, 2014, 12:17 AM
In a text file i have this way
DBC-Schwelle A 00 Bedingung_G011: false
i need to get output as :
DBC-Schwelle A
00
false
or
00
false
I am working on this ,as i said i am new to C# it takes time looking forward for u help....
Thanks
VulpesPosted Feb 18, 2014, 9:49 AM
The output is:
sampath mekaPosted Feb 18, 2014, 7:24 AM
string str1 = ((B48B20, XB1141) + PLUGIN_HYBRID + ECE)
Expected output:
B48B20+ PLUGIN_HYBRID + ECE
XB1141+ PLUGIN_HYBRID + ECE
Kindly help me how to acheive this
VulpesPosted Feb 18, 2014, 5:48 AM
The output is: