|
Can you show me ?
Also a tutorials or an example.
|
|
|
|
|
what you ask for is elementary string manipulation, read up on the String class, and start using some of its methods. If you don't feel comfortable programming in C# (or programming in general), I suggest you start by buying and studying an introductory book.
|
|
|
|
|
I have many books about c#, but can you show me an example for it ?
|
|
|
|
|
ahlm wrote: I have many books
Having them is not enough, you should study them. I'm not in a spoon feeding mood right now.
|
|
|
|
|
But do u know some good book titles then? I really need to learn it
|
|
|
|
|
It depends on your background.
I suggest you visit a book store and choose one or two. Read more here[^]
Year ago I liked "Microsoft Visual C#.NET Step by Step" by Sharp and Jagger.
|
|
|
|
|
Luc's being a 'meanie'! (although he makes a very good point)
Everything you need to do this as Luc said is in the String class - MSDN link[^].
A quick way to find out how to do something is to type the question into a search engine. For example, "how to replace a letter in string C#" with google returns this[^]. These results show many different ways of doing exactly what you want.
I don't mean to be sarcastic or condescending, but basic use of a search engine is an absolute requirement which you should always use as your first point of reference before asking on any programming site as you can be 100% sure that it has been asked and answered before unless it's a particularly technical or obscure question.
Once you have some answers, typing the class.methodname and appending MSDN will give you links to Microsoft's own documentation so you can read up on the finer points of the implementation possibilities of the options available.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks.
So this should work?
string str = "codeproject.com/script/";
str = str.Replace("codeproject.com/script/", "codeproject.com/scripl/"); <----
Also i have changed a "l"
|
|
|
|
|
That will work but it's not very versatile - if you just need to replace the word 'script'with 'scripl' then you should just use that part
string str = "codeproject.com/script/";
str = str.Replace("script", "scripl"); This doesn't deal with your original problem though, replacing one character a specific position with another. You could hard code something to alter just the 29th to 't', but then it wouldn't be reusable. I would create a method like
public static string ReplaceCharacter(string original, int index, char newChar)
{
} There are several methods which you will have come across through the google link.
There is String.Replace , but that replaces all occurences of a character or string inside the string plus you can't specify a position.
You could build a new string using a StringBuilder using the Substring up to the required character, appending the character you want and then appending the Substring after it. This would work but is a bit messy.
The method I would prefer is to convert the string to a char[] , change the character at the correct index then create a new string from the array. This would look something like this:
public static string ReplaceCharacter(string original, int index, char newChar)
{
if (index < original.Length)
{
char[] chars = original.ToCharArray();
chars[index] = newChar;
return new string(chars);
}
else
return original;
}
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I have a class that inherits System.ServiceProcess.ServiceBase and is overriding the OnStart (string[] args) method. Where do I call base.OnStart(args)? At the beginning of the method or at the end?
protected override void OnStart(string[] args)
{
base.OnStart(args);
}
Or:
protected override void OnStart(string[] args)
{
base.OnStart(args);
}
|
|
|
|
|
Normally OnXxx methods are used for raising events (and occaisionaly other logic that relates to an action but that should be documented). If your code in Do stuffrelies upon this event already being raised (or any other logic that might be in the base method being applied) then you should call it first. If it's important that your Do stuff is done before any events are raised etc then you should call it afterwards. If it doesn't matter then it doesn't matter!
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
DaveyM69 wrote: If it doesn't matter then it doesn't matter!
when you're right, you're right indeed!
|
|
|
|
|
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Sorry for not getting back sooner. In the OnStart method I'll be creating a couple of threads, a dozen or sockets and creating some objects but they won't depend on base.OnStart().
Let's say that something in my OnStart fails (file not found for example), how would I report that startup has failed and stop the startup of the service? Do I simply not call base.OnStart()?
modified on Sunday, December 6, 2009 9:15 PM
|
|
|
|
|
That depends on what else you do in your OnStart; I call base.OnStart in the middle:
protected override void
OnStart
(
string[] args
)
{
# if DEBUG
System.Threading.Thread.Sleep ( 60000 ) ;
# endif
this.oktoproceed = true ;
base.OnStart ( args ) ;
if ( this.when != null )
{
this.when.Start() ;
}
LogMessage ( this.ServiceName + " started" ) ;
return ;
}
(The Sleep gives me time to attach the debugger. when is a System.Timers.Timer .)
|
|
|
|
|
hey guys,
i wanted to program a windows CE device by c# and my purpose is to print a simple page. but in 'device application' windows form, there is no 'PrintDialog' nor 'PrintDocument' (and other necessary) classes for me to manage a print .
how can i print through a windows CE device?
much appreciated.
modified on Saturday, November 28, 2009 1:32 PM
|
|
|
|
|
How do you attach a printer to a windows CE device ? Do they have USB ports and printer drivers ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
yes exactly. i have a usb printer connected to my device and my windows recognizes it and the driver.
i can print with other applications in windows CE (like microsoft word) but i want my own application to print a page. how is it?
thanks.
|
|
|
|
|
I have several columns I want to print the column headers vertically and not horizontal.
I have found a method that works but does not meet the expectations speficied.
Option 1) (This way does not meet specifications but does work)
- I could loop thru the string placing a carrage return after each letter.
Option 2) (This way meets specifications and I can get it to print on the screen. However I can not get it to print onto the printer)
private void dgvReport_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)<br />
{<br />
<br />
if (e.RowIndex == -1 && e.ColumnIndex >= 4)<br />
{<br />
e.PaintBackground(e.ClipBounds, true);<br />
Rectangle rect = <br />
this.dgvReport.GetColumnDisplayRectangle(e.ColumnIndex, true);<br />
Size titleSize =<br />
TextRenderer.MeasureText(e.Value.ToString(), e.CellStyle.Font);<br />
if (this.dgvReport.ColumnHeadersHeight < titleSize.Width)<br />
this.dgvReport.ColumnHeadersHeight = titleSize.Width;<br />
<br />
e.Graphics.TranslateTransform(0, titleSize.Width);<br />
e.Graphics.RotateTransform(-90.0F);<br />
<br />
e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font,
Brushes.Black, new PointF(rect.Y, rect.X));<br />
<br />
e.Graphics.RotateTransform(90.0F);<br />
e.Graphics.TranslateTransform(0, -titleSize.Width);<br />
e.Handled = true;<br />
} <br />
<br />
}
This way actually rotates the column headers to ensure their vertical the same as their horizontal.
How can I print this way (Option 2)
|
|
|
|
|
What additional information is needed to aid in resolving this issue?
I need to be able to print my column names horizontal.
I can not seem to figure this out when going to the printer. Please help.
|
|
|
|
|
Hi every one.
I wana make a report from dataBase,Instead of using and showing it in crystalReport i want it in Word.
Can u help me please.Thank you .
CanI
|
|
|
|
|
You can get the data from the database using ADO.Net and then format it as per your need. To write the same to a word file, you can use interop.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Have a look at an open source project called Migradoc, this makes RTF files from data,
without word installed, you can export to word from the crystal viewer or use interop
but the MS Word product must be installed.
All the word versions will open RTF and this should be sufficient for a report
|
|
|
|
|
I am trying to connect a client to server using WCF.
The following code works when the server code is loaded (named pipe, same machine).
m_app is initialized as follows:
const string address = @"net.pipe://localhost/Pipe";
EndpointAddress ep = new EndpointAddress(address);
m_app = ChannelFactory<iservicecontract>.CreateChannel(new NetNamedPipeBinding(), ep);
I am trying to catch the exception EndPointNotFoundException. The catch block below initially used EndPointNotFoundException but didn't work so I tried CommunicationException.
I want to catch the situation where the server is not present.
What am I missing?
try
{
LoginResult result = m_app.DoLogin(username, password);
return result;
}
catch (CommunicationException e)
{
}
|
|
|
|
|
Perhaps you could just catch Exception , inspect the derived type, then recode to catch that exception? (I'm surprised CommunicationException didn't work).
/ravi
|
|
|
|