|
To remove newline from the end of string or other chars from the end of string
int pos=textBox1.Text.LastIndexOf(Environment.NewLine);
if (pos !=-1)
{
string text;
text=textBox1.Text.Remove(pos,Environment.NewLine.Length);
textBox1.Text=text;
}
Note: check the pos+length to insure that this he end of
string not just last newline in string
MCAD
-- modified at 10:51 Friday 2nd September, 2005
|
|
|
|
|
myText = myText.Replace("\r\n", "\r");
|
|
|
|
|
You could do a couple things: find the index of each undesired character using theString.IndexOf method, then remove that character using theString.Remove(index, 1). This method, while fairly simple to do, will cause lots of string allocations; for each string.Remove call, a new string will be created. Another way of doing this is to create a System.Text.StringBuilder using your string, then doing a strBuilder.Replace call to replace undesired characters with empty characters.
Perhaps the most efficient way of doing this would be to use a regular expression to swap out the undersireable characters from the end of the string. If you need help creating a regular expression, I recommend this website[^].
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
The tab character is chr(9). I assume that you want to remove the newline combination CR+LF, e.g. chr(13)+chr(10).
One way is to look for it at the end of the string, and remove them as long as there are any:
while (myString.EndsWith(Environment.NewLine)) myString = myString.Substring(0, myString.Length - Environment.NewLine.Length);
This works fine if there is just one or a few newline at the end of the string. If you expect to encounter a lot of newlines, you may want to find out how many there are before you remove them, as string manipulations are relatively slow.
---
b { font-weight: normal; }
|
|
|
|
|
Who can tell me how to create and delete data tables?
I want to manage Access database using ADO.NET with C#.
|
|
|
|
|
//create the database connection
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\db1.mdb");
//create the command object and store the sql query
OleDbCommand aCommand = new OleDbCommand(CREATE_TABLE_STATEMENT, aConnection);
try
{
aConnection.Open();
aCommand.ExecuteNonQuery();
//close the connection Its important.
aConnection.Close();
}
//Some usual exception handling
catch(OleDbException e)
{
Console.WriteLine("Error: {0}", e.Errors[0].Message);
}
}
}
|
|
|
|
|
Hi Every body
I have a usercontrol (Named DatePicker) with a property called 'Date'.This is the syntax of this property :
[Category("Date Info"),Bindable(true)]
public string Date
{
get
{return this.dateString;}
set
{this.dateString = value;}
}
This control also have some string properties (Day,Year and month) without '[Bindable(true)]'Attribute.I use this user control and bind the 'Date' property of this control to a string column of a DataView in my form :
this.datePicker1.DataBindings.Add("Date",this.dvDataSource,"Birthday");
When I delete all rows of dataview whith this code :
this.BindingContext[this.dvDataSource].RemoveAt(this.BindingContext[this.dvDataSource].Position);
and then try to add a new row using the following code,
this.BindingContext[this.dvDataSource].AddNew();
I receive the following Exception :
"DataBinding could not find a row in the list that is suitable for all bindings"
Note :
When I comment the line of code that contains instruction for Binding this property, everything works ok.I bound some other controls (Like DataGrid and TextBox) to the other columns of DataView.They haven't any problem !!
Please help me if anyone knows the answer.
Best Regards.
[ _ Always there is another way _ ]
|
|
|
|
|
I want to communicate two persons, which are on LAN, by voice using IP Address and broadcasting (Conferencing) also. what are the suitable ways to get this done and how.
1. DirectPlay 9.0 Managed
2. UDP Sockets
DirectPlay 9.0 is now obselete according to documentation what is the alternate to this one. If you have any code, ebook or any resource which you can share, send me please.
Thank you
Zeeshan
|
|
|
|
|
Well, Microsoft is "obsoleting" DirectPlay (along with DirectMusic, DirectInput, ...basically everything except Direct3d) in favor of using Windows APIs to accomplish these things. So if you're looking to do communication in a LAN, as long as both client and server are .NET based, then I'd recommend using .NET remoting. There are many examples on this site on how to use .NET remoting.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
Thanks Judah Himango
But .NET Remoting is socket base transfer of data which is slow in case of Voice. Can you please tell me how i can receive voice from mic and send to other node and transfer to speaker and vice versa.
I want to communicate through voice only. (Like InterCom or Waky Taky)
Thank you again for immediate reply.
Zeeshan
|
|
|
|
|
Voice-over-IP providers, as far as I know, use socket-based transferral of data. Intercom and other analog devices use radio frequency waves, which is not possible for digital, computer-based communication, unless of course you have some radio receiver card in the PCs attempting to do the communication.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
How can I give a "seperate" value to a specified item within the combobox? For instance, Say when the user selects "good" within the combobox, there will also be a value associated with it that will be displayed within a textbox. Thanks in Advance.
D
|
|
|
|
|
I am importing the items that populate the combobox from an XML doc. Is it possible to handle what I mentioned within the XML sheet?
D
|
|
|
|
|
You can create a custom class redefining the ToString() method.
The ComboBox uses the ToString() method to retrieve a string to display in the UI for each item.
<br />
class MyItem {<br />
<br />
private string name;
private string val;
<br />
public MyItem(string n, string v) {<br />
name = n;<br />
val = v;<br />
}<br />
<br />
public string ToString() {<br />
return name;<br />
}<br />
<br />
public string Content {<br />
get {<br />
return val;<br />
}<br />
}<br />
<br />
}<br />
<br />
ComboBox c = new ComboBox();<br />
c.Items.Add(new MyItem("good", "User choosed good"));<br />
<br />
<br />
ComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {<br />
textBox.Text = ((MyItem)c.SelectedItem).Content;<br />
}<br />
I hope
[ITA] Tozzi ha ragione: Gaia si sta liberando di noi.
[ENG] Tozzi is right: Gaia is obliterating us.
|
|
|
|
|
Thanks for the quick response. However, is there some way I could put all of the information into an XML file and pull it from that accordingly? I have most of the information in there as it is. Thanks again.
D
|
|
|
|
|
When I use "c.Items.Add(new MyItem("good", "User choosed good"));" it gives me an error: Class, struct, or interface method must have a return type and invalid tokd '(' in class, struct, or interface member declaration and then Type expected where "good" is at.
I think what you gave me may work if I can fix the bugs. I may be able to pass dataset rows to "MyItem" that would populate the combobox. Any help would be appreciated. Thanks again.
D
|
|
|
|
|
I got it to compile. However, when I try to read the data into the textbox it gives me an error. This is the code:
textBox1.Text = ((MyItem)c.SelectedItem).Content;
This is the error:
Object Reference not set to an instance of an object.
Thanks
D
|
|
|
|
|
Can you send the code snippet or the stack trace.
|
|
|
|
|
Maybe i've been a little rough... I've written the MyItem class on-the-fly directly in the messageboard. That should be only an example.
However I think it's a very strange behavior. In the code there are not evident errors... I really don't know how to help you. I'm so sorry...
[ITA] Tozzi ha ragione: Gaia si sta liberando di noi.
[ENG] Tozzi is right: Gaia is obliterating us.
|
|
|
|
|
Hi,
I want to create an application that when you connect to the internet via a dialup or broadband connection a timer will start and then work out according to you're exchange as to how much the connection cost.
Can someone please advice?
Thanks!
Illegal Operation
Making Computer Software Talk
|
|
|
|
|
Well, you can easily figure out how long your own application is running using the various Timer classes available out there. If you want to figure out if the machine is connected to the internet, you'll need to run your application as a Windows service, then monitor the state of the connection. Now, I believe you'll need to use the Win32 API (via P/Invoke) to check the status of the machine's internet connection. When the connection starts, start the timer. When the connection is disconnected, stop the timer. From there, it's just a matter of multiplying the time spent online by the rate.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
hi,everybody.
Who understand the function of Control.SetStyle and Control.Show?
How to make tow forms in the same layer?
|
|
|
|
|
dreamwinter wrote:
How to make tow forms in the same layer?
What do you mean? What do you intend for a layer?
dreamwinter wrote:
Who understand the function of Control.SetStyle and Control.Show?
AFAIK SetStyle is used to set some *graphics* bahaviors of the Control, such as DoubleBuffering, WMPainting...
Control.Show is used to show the control, for example after you called Control.Hide.
[ITA] Tozzi ha ragione: Gaia si sta liberando di noi.
[ENG] Tozzi is right: Gaia is obliterating us.
|
|
|
|
|
Has a 'dataGrid1' and assign to 'dataTable1', 'dataTable1' have 3 columns: Col1,Col2,Col3, and then:
Col1.ColumnName = "Col1";
Col2.ColumnName = "Col2";
Col3.ColumnName = "Col3";
Col1.DataType = System.Decimal;
Col2.DataType = System.Int32;
Col3.DataType = System.Decimal;
Col3.Expression = "Col1 * Col2";
Col3.ReadOnly = true; // it's auto set
Why at runtime, edit Col1, Col2 of the 'dataTable1' and then leave to other row, but Col3's value has not change yet, has not any be computed?
Additional:
I had try to new a 'dataRow1', and then give value to dataRow1[0], dataRow1[1], and at last 'Add()' this row in 'dataTable1'. At this time, run dataTable1.Refresh() and found that 'Col3' shown correct. Why at this time the Expression could be used.
Why learn more, unaware more?
|
|
|
|
|
hi to all,
does any one knows how to use graphical control in a c# win application.
i have an interface that display a planning of an employe and i want to do that graphically.
does any one knows if such control exist in c# ?
if not does someone have any suggestions ?
best regards and thanks in advance
fady
|
|
|
|