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

VulpesRank #55 · 29.2K reputationPosted Feb 19, 2014, 2:15 AM EST
The output is:
VulpesRank #55 · 29.2K reputationPosted Feb 18, 2014, 12:48 AM EST
The output is:
sampath meka39 reputationPosted Feb 18, 2014, 2:24 AM EST
string str1 = ((B48B20, XB1141) + PLUGIN_HYBRID + ECE)
Expected output:
B48B20+ PLUGIN_HYBRID + ECE
XB1141+ PLUGIN_HYBRID + ECE
Kindly help me how to acheive this
VulpesRank #55 · 29.2K reputationPosted Feb 18, 2014, 4:49 AM EST
The output is:
sampath meka39 reputationPosted Feb 18, 2014, 7:17 PM EST
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
sampath meka39 reputationPosted Feb 19, 2014, 7:38 PM EST
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 ...
VulpesRank #55 · 29.2K reputationPosted Feb 20, 2014, 5:18 AM EST
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.
VulpesRank #55 · 29.2K reputationPosted Feb 20, 2014, 7:20 AM EST
The output is:
sampath meka39 reputationPosted Feb 20, 2014, 10:54 PM EST
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.....
sampath meka39 reputationPosted Feb 20, 2014, 11:47 PM EST
Thanks u
VulpesRank #55 · 29.2K reputationPosted Feb 21, 2014, 1:07 AM EST
"(?:[^a-z0-9 _]|(?<=['\"])s)"
sampath meka39 reputationPosted Feb 26, 2014, 10:23 PM EST
VulpesRank #55 · 29.2K reputationPosted Feb 27, 2014, 4:31 AM EST
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.