|
The simplest solution is to use a regular expression:
Regex.Replace(inputString, @"[\s]*$", "")
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
this is the most efficient and accruate way, thanks very much.
|
|
|
|
|
you can do
input_3 = inputstr.Substring(0, inputstr.LastIndexOf(" "));
will give you the result you want.
theLizard
|
|
|
|
|
Unfortunately, that turns out not to be the case.
It will remove all data from the last occurance of a space to the end:
"A<space>B<space>C<space><space>" becomes "A<space>B<space>C<space>"
"A<space>B<space>C" becomes "A<space>B"
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Oops, less haste,
If I could not use trim()
it should have been something like
<br />
<br />
if(string.LastIndexOf(" ") = string.Length)<br />
{<br />
string = string.Substring(0, string.Length-1);<br />
}<br />
<br />
But the answer from OriginalGriff seems to be the one, I have also learned.
theLizard
|
|
|
|
|
Make it a while loop and use a comparison operator rather than assignment.
|
|
|
|
|
oops (again, bugger) left out one of these = and yes a while would be appropriate if more than one at end of string.
I'm having an off day
theLizard
|
|
|
|
|
There are plenty of ways of doing this. Here is one:
You can make use of LastIndexOf and Replace method along with the Length property. Check the last index of the space and if it is equal to the length of the string, replace it with nothing. You can also use the Remove method instead of Replace.
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...!!
|
|
|
|
|
Doesn't achieve what he asked for: it only removes the last space, not all trailing spaces.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Do that recursively.
/This approach can win the worst approach award.
//No, I can beat this one too.
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...!!
|
|
|
|
|
Mmmm! I love the smell of sledgehammer in the morning!
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Just the smell. Blow - never.
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...!!
|
|
|
|
|
I'm writting a multi-media classroom use c#.
I Want Send The Teacher' Computer screen to Every Student screen.
Thanks.
|
|
|
|
|
|
Hello guys,
I would like to have a wrapper for Rcom server in C#. I do not know what a wrapper is or how to create it.
This is what i did and i do not know if i am right or wrong.
I opened a project in C# which is integrated to R, using two dll files and this is what i did:
Open Project -> References -> Add References -> COM -> RCOM 1.0 type library (located at library/rcom/libs/rcom_srv.tlb)
This creates a dll file in my system named Interop.RCOMServerLib.dll. Is this what is meant by the wrapper file. I have no clue, its just a wild guess.
I need some help here.
Thanks,
SJ.
|
|
|
|
|
I have been suffering with dial-up internet access for many years, but lately it has been getting worse. I would like to write an application using C# or C++ to monitor what programs are using, and maybe hogging the connection. If anyone could point me in the best direction to get started, I would much appreciate any guidance you could give me.
|
|
|
|
|
Why do you want to write your own? It would be a very complex project...
Net Limiter[^] can show you the information your interested in
Hope this helps
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
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
|
|
|
|
|
Thanks I will check it out. But I was look for a winter time project to pass the time....(maybe way over my head anyway)..
Thanks again..
|
|
|
|
|
namespace Passing_Data
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(textBox1.Text);
frm.Show();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
FORM 2:
namespace Passing_Data
{
public partial class Form2 : Form
{
public Form2(String strTextBox)
{
InitializeComponent();
label1.Text = strTextBox;
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
this code allows me to enter data in textbox on first form and hit button and see it displayed on second form in label.
is there a way to enter data in textbos on first form and hit button and see data entered into combobox on second form?
thank you
|
|
|
|
|
Yes, using events. See this post[^] that I made a few days ago, as well as a working sample there is also a link to an article I wrote that explains events in much more detail if you want to gain a proper undestanding of the implementation but aimed at a beginner to events.
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)
|
|
|
|
|
Example 1.
public class Employees
{
public static List<Employee> ListEmployees;
public static void FillEmployees()
{
ListEmployees = FillFromSQL();
}
}
class Program
{
static void Main(string[] args)
{
Employees.FillEmployees();
}
}
Then whenever I need to access the list of employee objects I can just call Employees.ListEmployees.Find(e => e.Name == "Mike"); I can call this anywhere in my scope because is static.
Or Example 2
public class Employees
{
private List<Employee> ListEmployees;
public void FillEmployees()
{
ListEmployees = FillFromSQL();
}
public void FindEmployee(Predicate<Employee> e)
{
return ListEmployees.Find(e);
}
}
class Program
{
Employees employees;
static void Main(string[] args)
{
employees = new Employees();
employees.FillEmployees();
}
}
Any help would be much appreciated.
Or if you have a better way of doing it that would be a great help.
|
|
|
|
|
I don't know the entire context of your program of course, but I think I'd use a Dictionary<string, Employee> (where the string is the name)
|
|
|
|
|
Employees can have the same name though. I do see what you saying, but problem lies more on the way I build my classes. Having most of the list static so I can access them from anywhere. I don't think this is right though. Well it is right but proberly doesn't follow best practises.
|
|
|
|
|
Bardy85 wrote: Well it is right but proberly doesn't follow best practises.
A "best practice" often turns into a golden hammer. There's a lot of ways to load data, some make sense in a webapp, others make more sense in a console-application. Using NHibernate from a console-app just to update the name of a single employee would be overkill.
Most answers here will be variations on the ActiveRecord-pattern to store a single record. It would also make sense to store multiple records in some kind of collection[^].
I are Troll
|
|
|
|
|
I would do this:
public class Employee
{
}
public class EmployeeList : List<Employee>
{
public EmployeeList(bool populateNow)
{
if (populateNow)
{
GetFromDatabase();
}
}
public void GetFromDatabase()
{
this.AddRange(blah blah);
}
}
EmployeeList employees = new EmployeeList(true);
The list should know how to load itself, and can take care of all the nasty stuff behind the scenes and abstracted out of the UI code.
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|