| View previous topic :: View next topic |
| Author |
Message |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Wed Dec 10, 2008 10:31 pm Post subject: [C#]Split |
|
|
Split isn't working for me
I do this
| Code: |
void replace(){
string[] lines = richTextBox1.split('\n');
foreach (string s in lines)
{
if (s == "SetMousePos")
{
string message = s.Split(' ')[1];
uint myX = message.Split(',')[1];
uint myY = message.Split(',')[2];
pMouse.MousePos(myX, myY);
}
}
} |
and I get these errors:
| Code: |
Error 1 'System.Windows.Forms.RichTextBox' does not contain a definition for 'split' and no extension method 'split' accepting a first argument of type 'System.Windows.Forms.RichTextBox' could be found (are you missing a using directive or an assembly reference?) C:\Users\Landon\Desktop\C#\Teleporter\Teleporter\Form1.cs 52 43 Teleporter
Error 2 Cannot implicitly convert type 'string' to 'uint' C:\Users\Landon\Desktop\C#\Teleporter\Teleporter\Form1.cs 58 32 Teleporter
Error 3 Cannot implicitly convert type 'string' to 'uint' C:\Users\Landon\Desktop\C#\Teleporter\Teleporter\Form1.cs 59 32 Teleporter
|
Help appreciated :] sorry for asking many questions!
_________________
| qwerty147 wrote: |
| ghostonline wrote: |
what world are you in?
|
bera
but i live in NZ
|
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed Dec 10, 2008 10:47 pm Post subject: |
|
|
What are you trying to do, parse something?
Perhaps you'd be better off taking a look at substrings.
|
|
| Back to top |
|
 |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Wed Dec 10, 2008 11:57 pm Post subject: |
|
|
fixed, close please.
_________________
| qwerty147 wrote: |
| ghostonline wrote: |
what world are you in?
|
bera
but i live in NZ
|
|
|
| Back to top |
|
 |
Jonyleeson Master Cheater
Reputation: 0
Joined: 03 May 2007 Posts: 484 Location: Hérault, France
|
Posted: Thu Dec 11, 2008 12:38 pm Post subject: |
|
|
You're trying to split the RichTextBox itself, you should be splitting the Text property :
| Code: | | string[] lines = richTextBox1.Text.Split('\n'); |
As for
| Code: | uint myX = message.Split(',')[1];
uint myY = message.Split(',')[2]; |
You have to cast the string to a uint :
| Code: | uint myX = uint.Parse(message.Split(',')[1]);
uint myY = uint.Parse(message.Split(',')[2]); |
|
|
| Back to top |
|
 |
ElJEffro Grandmaster Cheater Supreme
Reputation: 0
Joined: 15 Apr 2007 Posts: 1881 Location: La Tierra
|
Posted: Mon Dec 15, 2008 4:25 pm Post subject: |
|
|
| CoolCat wrote: | You're trying to split the RichTextBox itself, you should be splitting the Text property :
| Code: | | string[] lines = richTextBox1.Text.Split('\n'); |
As for
| Code: | uint myX = message.Split(',')[1];
uint myY = message.Split(',')[2]; |
You have to cast the string to a uint :
| Code: | uint myX = uint.Parse(message.Split(',')[1]);
uint myY = uint.Parse(message.Split(',')[2]); |
|
| Code: |
uint myX;
uint myY;
if (!uint.TryParse(message.Split(',')[1], out myX) || !uint.TryParse(message.Split(',')[2], out myY))
MessageBox.Show("Error parsing parameters in line whatever");
|
That way you won't get an exception and you'll know if those are valid unsigned ints next to the commas
|
|
| Back to top |
|
 |
|