|
mimimimilaw wrote: if I want to cut the "page=123", how to do it?
string str = "www.abc.com?page=123&no=456";<br />
str = str.Replace("page=123&","");<br />
MessageBox.Show (str);
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
This works only if page is always 123, which is probably not the case.
Try this instead:
Regex.Replace("www.abc.com?page=123&no=456", @"(?<urlstart>.*\?)page=\d+&(?<urlend>.*)", @"${urlstart}${urlend}")
-----
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
I know.. but he doesn't ask for it..
anyway, thanks for your code..
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
Try using the Uri class. You would probably want to do something like
Uri builder = new Uri("www.abc.com?page=123&no=456");
string[] parts = builder.Query.Split('&');
string final = String.Format("{0}?{1}", builder.AbsolutePath, parts[2]);
|
|
|
|
|
Could anyone please help me out in auto-generating a property in a class in a following format:
public System.Int64 RollNumber
{
get
{
System.Int64 rollNo = (System.Int64 )this["@roll_number"];
return rollNo;
}
}
I am able to generate the property with the return statement and the other stuff, but i am not able to Generate the assignment statement i,e :
System.Int64 rollNo = (System.Int64 )this["@roll_number"];
Please Help.
Thanks,
Ramesh
|
|
|
|
|
rameshbhojan wrote: auto-generating
?
Did you mean this?
public System.Int64 RollNumber
{
get
{
System.Int64 rollNo = (System.Int64 )this["@roll_number"];
return rollNo;
}
set
{
this["@roll_number"] = (proper_cast)value;
}
}
Greetings - Gajatko
|
|
|
|
|
Hi Gajatko,
All i wanna generate is :
public System.Int64 RollNumber
{
get
{
System.Int64 rollNo = (System.Int64 )this["@roll_number"];
return rollNo;
}
}
i don need the set statement....
anyways gimme the solution you have...... if i am able to generate the way you said then also it is fine!!!!
Thanks,
Ramesh
|
|
|
|
|
The class your looking for is CodeVariableDeclarationStatement.
CodeMemberProperty prop = new CodeMemberProperty();
prop.Name = "RollNumber";
prop.HasGet = true;
prop.Attributes = MemberAttributes.Public;
prop.Type = new CodeTypeReference("System.Int64");
prop.GetStatements.Add(new CodeVariableDeclarationStatement("System.Int64", "rollNo",
new CodeCastExpression("System.Int64",
new CodeIndexerExpression(
new CodeThisReferenceExpression(),
new CodePrimitiveExpression(
"@roll_number")))));
prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("rollNo")));
But why bother with the variable when you could just return (System.Int64 )this["@roll_number"];
|
|
|
|
|
Hi All,
I have used CodeDOM in .net to auto-generate C# code, which in essence generates a class file having a class along with its member fields, methods and properties.
However, i don know how to generate the following line of code:
private const string NAME = "CSharp";
Here, i have a generate a CodeMemberField which is a constant string with a private specifier as shown above.
Please send me the sample code which would help me to auto-generate the above line of code.
Thanks,
Ramesh
|
|
|
|
|
How do you auto-generate c# code? You can build your code from strings and then compile it into dll file or executable dynamically during runtime
|
|
|
|
|
ya .... tats wat i meant Giorgi....
as u mentioned i can build the code from string...
in the content of tat string i want one such statement which i mentioned in my query above........
do u know how to do tat??????
Thanks,
ramesh
|
|
|
|
|
So it means that you need help in string manipulation? You need string which says private const string NAME = "CSharp"; ? I guess your problem is having " inside you string isn't it?
|
|
|
|
|
No Giorgi.... m speakin of using CodeDOM to do tat...
However, i would also like to know the solution for the problem you mentioned above.... i mean how do i have " inside my string usually in string manipulation???
|
|
|
|
|
So you want to generate string content using CodeDOM? I'm not aware how to that but why would you want it? Why can't you just build your source from strings?
|
|
|
|
|
Well..... i started with CodeDOM....
Actually i am creating a whole C# file which has a namespace.... a class.... its member fields.... methods..... properties.... i have been able to do a major part.... the places where i had issues.... are the ones i have posted....
so i need a solution to tat using "MemberField" class in CodeDOM...
hey Giorgi...... u din tell me how to do tat string manipulation stuff.... i mean if a wanna have " in my string... then how do i do tat????
-- modified at 7:51 Tuesday 21st August, 2007
|
|
|
|
|
rameshbhojan wrote: i mean if a wanna have " in my string... then how do i do tat????
Search for escape characters.
As for your first question, will your code be changing during runtime or do you have some static piece of code you want to compile during runtime?
|
|
|
|
|
The Code will change Giorgi During Runtime...... its not static.....
anyways i ve got my answer from Dave........ u can check the same......
Thanks,
ramesh
|
|
|
|
|
CodeMemberField field = new CodeMemberField("System.String", "NAME");
field.InitExpression = new CodePrimitiveExpression("CSharp");
field.Attributes = MemberAttributes.Const | MemberAttributes.Private;
field.Type = new CodeTypeReference("System.String");
|
|
|
|
|
Thanks Dave for both of your answers its all fine now........
hey Dave do you know how to creat regions using CodeDOM
and i have one more issue.....
all the statements inside a method or a constructor are aligned to the extreme left......
i want it to be properly indented.
for example:
public Data(string name, string age, string city)
{
this.m_name=name;
this.m_age=age;
this.m_city=city;
}
this i wat i am getting instead of getting a well indented code like:
public Data(string name, string age, string city)
{
this.m_name=name;
this.m_age=age;
this.m_city=city;
}
How do i get it indented....
|
|
|
|
|
Sorry Dave,
i don know how to add a section of code here....
both my indented version and non-indented version look the same above!!!! Sorry..... but i hope u got wat i wanted to say.......
i want the statement inside the method to be indented to one more tab towards right
|
|
|
|
|
You can specify a different indent string inside CodeGenerationOptions. But there isn't much else you can do, you might be better off just formating the document in visual studio afterwards.
CodeGeneratorOptions options = new System.CodeDom.Compiler.CodeGeneratorOptions();
options.IndentString = "\t";
cs.GenerateCodeFromMember(prop, w, options);
|
|
|
|
|
and wat bout getting the #region and #endregion Dave????
|
|
|
|
|
Are there any function for this ?
Thank =)
|
|
|
|
|
You can use the MeasureString() function in GDI+, it takes a string and a font and returns a SizeF object I believe containing the size of the string. I believe the function is available from the graphics object, not sure though..
|
|
|
|
|
Yes it is available, however it is stupidly an instance method of Graphics object, instead a static one, so one needs CreateGraphics().MeasureString(...) to do the trick.
Greetings - Gajatko
|
|
|
|