Need help with RegEx

  • Thread starter Thread starter Alexander Vasilevsky
  • Start date Start date
A

Alexander Vasilevsky

This code
Regex ge = new Regex("[,\f/]");

string format = ge.Replace("8 kBit/s, 8,000 Hz, Mono", "_");

returns

"8 kBit_s_ 8_000 Hz_ Mono"
and I need
"8_kBit_s_ 8_000_Hz_ Mono"

http://www.alvas.net - Audio tools for C# and VB.Net developers
 
This code
Regex ge = new Regex("[,\f/]");

string format = ge.Replace("8 kBit/s, 8,000 Hz, Mono", "_");

returns

"8 kBit_s_ 8_000 Hz_ Mono"
and I need
"8_kBit_s_ 8_000_Hz_ Mono"

Could you explain the rules for that? It's not clear in which
situations you'd want a space to be replaced by _ and in which
situations you wouldn't.

(What is the form feed in the regular expression meant to be doing, by
the way?)

Jon
 
I want to replace all white space " " to "_". See below

"8 kBit_s_ 8_000 Hz_ Mono"
"8_kBit_s_ 8_000_Hz_ Mono"

http://www.alvas.net - Audio tools for C# and VB.Net developers


"Jon Skeet [C# MVP]" <[email protected]> ???????/???????? ? ????????
?????????:
This code
Regex ge = new Regex("[,\f/]");

string format = ge.Replace("8 kBit/s, 8,000 Hz, Mono", "_");

returns

"8 kBit_s_ 8_000 Hz_ Mono"
and I need
"8_kBit_s_ 8_000_Hz_ Mono"

Could you explain the rules for that? It's not clear in which
situations you'd want a space to be replaced by _ and in which
situations you wouldn't.

(What is the form feed in the regular expression meant to be doing, by
the way?)

Jon
 
The decision proved very easy
Regex ge = new Regex(@"\W");

;)


http://www.alvas.net - Audio tools for C# and VB.Net developers


"Jon Skeet [C# MVP]" <[email protected]> ???????/???????? ? ????????
?????????:
This code
Regex ge = new Regex("[,\f/]");

string format = ge.Replace("8 kBit/s, 8,000 Hz, Mono", "_");

returns

"8 kBit_s_ 8_000 Hz_ Mono"
and I need
"8_kBit_s_ 8_000_Hz_ Mono"

Could you explain the rules for that? It's not clear in which
situations you'd want a space to be replaced by _ and in which
situations you wouldn't.

(What is the form feed in the regular expression meant to be doing, by
the way?)

Jon
 
Alexander Vasilevsky said:
I want to replace all white space " " to "_". See below

to match any Whitespace use \s
"8 kBit_s_ 8_000 Hz_ Mono"
"8_kBit_s_ 8_000_Hz_ Mono"

there is a space before 8 and before Mono wich is not replaced. I suppose
this is a typo.

Christof
 
Alexander Vasilevsky said:
The decision proved very easy
Regex ge = new Regex(@"\W");
this matches all characters, wich are nor letter nor digit. So it will also
replace some non-whitespace charackters. E.g. +*#()&%

Christof
 
I want to replace all white space " " to "_". See below

"8 kBit_s_ 8_000 Hz_ Mono"
"8_kBit_s_ 8_000_Hz_ Mono"

That hasn't replaced all spaces with _ - you've still got a space
before the 8 and before the M. Do you *actually* want the result to be

"8_kBit_s_8_000_Hz_Mono"

?

It's really, really important to be absolutely accurate in what you
want, otherwise we won't be able to help you.

Jon
 
Back
Top