|
Use regex grouping to match the bits you want to keep and build a new string, or to match the bits you want to remove, and then remove them.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Yay! Thanks lots Christian Graus.
j.t.
|
|
|
|
|
jay_t55 wrote: need to extract the words 'extract this!':
<title>Extract this!
Here you go..
string str = "<title>Extract this!</title>";
Regex RE = new Regex(@"(<title> )(\w|\S|\s )+(</title> )");
MatchCollection MC = RE.Matches(str);
if (MC.Count == 0) MessageBox.Show("No match");
foreach (Match M in MC)
{
string trimStr = "</title>";
MessageBox.Show(M.ToString().Trim(trimStr.ToCharArray()));
}
8.Kelvin()
{
while (!(the machine can program itself))
Wont_stop_coding = true;
}
|
|
|
|
|
Wow! Thank you so much 8Kelvin, very much appreciated!!
Jay.
j.t.
|
|
|
|
|
What you want is an HTML parser (google is your friend). Don't mess around with regex because you'll spend a lot of time trying to figure it out. Believe me - downloading a parser will be much faster.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hear hear! This is a wheel best not reinvented.
|
|
|
|
|
Hey guys
I need to get the size of a string in bytes, how do i do that
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Harvey Saayman wrote: the size of a string in bytes
what size? what is your purpose?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Im trying to send a request to a IM(MXit) server, to protocol documentation states that the length of the request must be pre-pended to the request...
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Hi,
if the API you are using expects a Unicode string, then I would expect the length is the number of characters, not bytes.
in the more likely case the API expects a byte array, you would need an Encoding (maybe Encoding.ASCII, Encoding.UTF8, or new Encoding(1252)) and use its GetBytes() method. In such case the length would be the length of the byte[].
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
You mean the size of the string in a specific encoding? for example,
Encoding.UTF8.GetByteCount(theString);
Or the size of a string object in memory? which depends on implementing platform[^]
Eslam Afifi
|
|
|
|
|
If i have a string, lets say the string is "System.Float".
Is there anyway i can get the type from that string? (ie a float).
And do something like this:
Float f = new GetMagicTypes<"System.Float">();
|
|
|
|
|
Huh?
You can get the type using: Type.GetType("System.Single"), etc, but you can't use that as a template argument.
And your example is going to create a GetMagicTypes object, not a float.
GetMagicTypes<float> f = new GetMagicTypes<float>();
What are you trying to accomplish?
- S
50 cups of coffee and you know it's on!
A post a day, keeps the white coats away!
|
|
|
|
|
What im doing is that im parsing the object type from xml, so i need a way to allocate an object of the type in the string.
Something like this then maybe:
Float f = new<type.gettype("system.float")>();
Ofcourse i could do this:
if("System.Float" == type)
Float f = new System.Float;
elseif("System.Boolean" == type)
Boolean b = new System.Boolean;
But that is an unnessecary thing if c# has support for string<->type conversion
|
|
|
|
|
Well...you can't know at compile time what you're going to get at runtime, so you can't strongly type it.
If you want the xml value to be a float, then you'll have to coerce it.
float f;
float.TryParse(your xml value, out f);
Same with all the other types, int, bool, etc.
- S
50 cups of coffee and you know it's on!
A post a day, keeps the white coats away!
|
|
|
|
|
Hi,
have a look at the Activator class and its CreateInstance method.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Awesome! many thanks, just what i was looking for
|
|
|
|
|
This will still just get you an object, so if you want to do anything with it, you'll have to cast it to the type you want, which might be fine for what your doing?
- S
50 cups of coffee and you know it's on!
A post a day, keeps the white coats away!
|
|
|
|
|
A) This may be a good place to use var .
B) Accessing Reflection can be time-consuming, so I prefer to cache the results.
C) Typically, in situations like this, I use a Dictionary. Here I might suggest a Dictionary<string,System.Reflection.ConstructorInfo> . Populate it with the expected/allowed types your application should support. Then something like:
var x = dic [ somestring ].Invoke() ;
would invoke the constructor and return an instance of whatever type was requested (or fail). However, it's Sunday morning and I'm still on my first cup of coffee, so I don't expect the above syntax to be correct (I'm pretty sure it isn't, but it should communicate the concept well enough).
D) If you want to support types that aren't known at compile time, you will need to learn how to dynamically load assemblies. There are several articles on that here.
|
|
|
|
|
Real programmers start lettering with @) not A)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
A is just a meaningless label. Maybe I'll use GUIDs next time.
|
|
|
|
|
|
Hi all,
Can any one please tell me that how can i change the color of second line in rich text box?
My requirement is first line in richtext box should be blue and second line should be red.
Thanks in advance
Lijo
|
|
|
|
|
select the text and change selection color
e.g.
RTB.SelectionColor = Color.Red;
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
First you need to change the color of the text before putting it in the rtb.
rtb.SelectionColor = System.Drawing.Color.Red;
rtb.AppendText(outText);
changing other attributes
rtb.SelectionColor = System.Drawing.Color.Blue;
System.Drawing.Font fBold = new System.Drawing.Font("Courier New", 10, fontBold);
rtb.SelectionFont = fBold;
rtb.AppendText(outText);
good luck
|
|
|
|