|
Hi,
kindly let me know that, how may I split following text into strArray1?
string[] strArray1;
"0000061050","APPLE","500","17.69","20091122","14:15:17"
Thank you in Advance
(Riaz)
|
|
|
|
|
M Riaz Bashir wrote:
string[] strArray1;
"0000061050","APPLE","500","17.69","20091122","14:15:17"
This already looks like an array, are you sure you are asking the right question?
|
|
|
|
|
but when I try to split it, it gives me following answer with slashes
"\"0000061050\"\"APPLE\""
|
|
|
|
|
M Riaz Bashir wrote: but when I try to split it, it gives me following answer with slashes
"\"0000061050\"\"APPLE\""
I am afraid this is not a very good explanation. Can you post the actual code that you use, showing the results that you are getting.
|
|
|
|
|
Those slashes aren't really there.
|
|
|
|
|
Trust us, if you have:
string inString = "1234,5223,Apple,Bank";
string[] bits = s.Split(',');
foreach(string s in bits)
{
Console.WriteLine(s);
} You will see it works!
The extra slashes you can see in the debugger are confusing, but they are only there to "escape" the double quote characters - just as you would type them into a string. You will get used to it eventually, everyone does!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
"Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"
|
|
|
|
|
It seems the series of double quotes itself is part of the string and the debugger escapes them with a \ (slash) to show them apart.
|
|
|
|
|
Dear All,
I have a datagridview which has three combobox column binded with DataSource and the datagridview is also binded with datasource.
As i have set the displaymember of comboxBoxColumn to "ColName" and ValueMember to "ColID" binding is ok.
when Im selecting something from those ComboBoxColumn while leaving that the value member appears at comboBox not the display member, Why the value member appears?
I have no other events for datagridview
Your cooperation is really appreciated
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
Anybody knows how to set up checkbox column in a dataGridView, after setting the dataGridView1.DataSource?
At first the datagridview does not have any column, so after setting the dataSource it will create column automatically, but I don't know how to automatically set the column to be checkbox type.
Thanks.
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:59am.
|
|
|
|
|
There's no need to add a new one. after setting the data source, the column is already there. I just need to change its type to be checkbox, but couldn't find a way to do that.
|
|
|
|
|
Why not simply define the bound columns at design time instead of autogenerating them?
|
|
|
|
|
I'm having trouble getting a schedule generator working properly. The way I have my program structured, there are 32 teams, all of which are a part of the "league". For the schedule generator, each team gets paired with another team for a game for 16 times (16 weeks). The specific problem is each team's schedule doesn't consist of more than 5 games maximum. (Each team should have 16 games.) In fact, it unusually varies from 1 game to 5 games. for each team's schedule.
I can't figure out what is wrong. Perhaps someone can point out my problem for me.
This is in my Team class:
[code]
private List<Game> games = new List<Game>();
public ReadOnlyCollection<Game> Games { get { return games.AsReadOnly(); } }
public void AssignGame(Game game)
{
games.Add(game);
}
public IEnumerable<Game> GamesWon { get { return games.Where(f => f.Played && f.Winner == this); } }
public IEnumerable<Game> GamesLost { get { return games.Where(f => f.Played && f.Winner != this); } }
[/code]
This is in my league class:
[code]
private const int HOME = 0;
private const int AWAY = 1;
private List<Team> teamList;
public ReadOnlyCollection<Team> Tms { get { return teamList.AsReadOnly(); } }
public int GetRanking(Team team)
{
TeamRankingComparer trc = new TeamRankingComparer();
List<Team> copyOfTeams = teamList.ToList();
copyOfTeams.Sort(trc);
return copyOfTeams.IndexOf(team) + 1;
}
private List<Game> games = new List<Game>();
public ReadOnlyCollection<Game> Games { get { return games.AsReadOnly(); } }
public void Schedule()
{
games.Clear();
Random r = RandomFactory.Create();
int weeks = 16;
for (int i = 0; i <= weeks; i++)
{
foreach (Team team in Teams)
{
List<Team> opponents = new List<Team>();
opponents.AddRange(Teams.Where(t => t != team));
Team opponent = opponents[r.Next(0, opponents.Count)];
if (!games.Any(g => g.Home == team && g.Away == opponent) && !games.Any(g => g.Home == team || g.Away == team))
{
games.Add(new Game(team, opponent));
}
else if (!games.Any(g => g.Home == team || g.Away == team))
{
games.Add(new Game(opponent, team));
}
}
}
}
[/code]
Other classes:
[code]
static class RandomFactory
{
private static Random globalRandom = new Random();
public static Random Create()
{
lock (globalRandom)
{
Random newRandom = new Random(globalRandom.Next());
return newRandom;
}
}
}
public class Game
{
public Game(Team home, Team away)
{
Home = home;
Away = away;
Home.AssignGame(this);
Away.AssignGame(this);
}
public Team Home { get; private set; }
public Team Away { get; private set; }
public Team Winner { get; private set; }
public bool Played { get { return Winner != null; } }
public void OnPlayed(Team winner)
{
Winner = winner;
}
}
internal class TeamRankingComparer : IComparer<Team>
{
public int Compare(Team team1, Team team2)
{
int team1Wins = team1.GamesWon.Count();
int team2Wins = team2.GamesWon.Count();
if (team1Wins > team2Wins)
{
return 1;
}
else if (team2Wins > team1Wins)
{
return -1;
}
else if (team1Wins == 0 && team2Wins == 0)
{
return String.Compare(team1.Name, team2.Name, true);
}
else
{
return 0;
}
}
}
public static class PrintScheduleStatistics
{
public static void PrintTeamStatistics(Team team)
{
foreach (Game g in team.Games)
{
string venue = "Home";
Team opponent = g.Away;
if (g.Home != team)
{
venue = "Away";
opponent = g.Home;
}
Console.WriteLine(String.Format("{0} to {1}", venue, opponent.Name));
}
}
}
[/code]
This call is in my Main() method:
[code]
League league = new League();
LoadRosters(league);
league.Schedule();
PrintScheduleStatistics.PrintTeamStatistics(league.Teams[1]);
[/code]
|
|
|
|
|
Why does your RandomFactory.Create work the way it does?
Surely you realize that it won't increase the entropy of your random numbers
I can't think of anything else it might be expected to accomplish, but you might have a perfectly legitimate reason to "restart" your PRNG with a seed that is a value from the old PRNG
|
|
|
|
|
Well it's no wonder is it?
For each team in the league, you loop through the 16 weeks.
For each week, you draw an opponent at random.
If there are no games (team vs opponent) in the league
AND no games where the team is either the home team or the away team
=> create (team vs opponent) game
if (!games.Any(g => g.Home == team && g.Away == opponent) && !games.Any(g => g.Home == team || g.Away == team))
..
else if (!games.Any(g => g.Home == team || g.Away == team))
First, you clearly didn't mean what your code says - that a game should only be created if there are no games where the current team plays either at home or away. Second, you've forgotten that if your draw results in a game that already exists you can't just move on to the next week without creating a game!
I'm not sure I've understood exactly what you *want* to happen, but if you want to generate a normal leage where all teams play all the other teams once at home and once away, why not just create them systematically using a nested loop and randomize the schedule afterwards?
Or, if it's not a normal league but more of a sort of cup, why not do like in a real draw and remove the teams that have been drawn so you can't draw the same combination again?
|
|
|
|
|
Hello.
How to do, so when i click a button, you can choose a place, where the richboxtext shall load from?
It's a kind of a little texteditor
Ahlmo
|
|
|
|
|
Have a look at OpenFileDialog class, and study some of the articles here at CodeProject. Just search for editor, or RichTextBox.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
What?
I dont understand what do u mean?
Can you help me plx
|
|
|
|
|
|
Which books are good for this kind of coding?
|
|
|
|
|
Sorry, I seldom recommend books as their value very much depends on someones background and prior knowledge;
I tend to like the Microsoft Step by Step series; e.g. "MicroSoft Visual C#.NET Step by Step" by John Sharp and Jon Jagger.
What I do recommend is described here[^].
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Ok, but can u give me an example plz Can't get my to work :S
|
|
|
|
|
You should be more concerned with learning programming than with getting a program to work, simply because the other way around is an unnatural order to proceed in, and thus a very difficult way to go about it. If you don't want to learn programming there are probably plenty of free programs on the market that do all you want and more.
That said, this is all there is to showing a dialog and reading the contents of a text file:
string readTextFile()
{
var dlg = new OpenFileDialog();
if (dlg.ShowDialog() != DialogResult.OK) return null;
using (StreamReader sr = File.OpenRead(dlg.FileName))
return sr.ReadToEnd();
}
This is a simplistic implementation. Normally you'd want to add the dialog as a component to your form, just because that will let you set filters or other properties using the designer rather than coding, and use that dialog in the method. If you were to support huge files you also might not want to read the entire file since the user won't be able to view more than a tiny bit of it at a time and it's kind of wasteful to keep it all in memory (and may not be possible to keep it all in the textbox control at once). But given that you couldn't figure out how to read a file even with links to articles about the subject I think you should just forget about large files.
Hopefully you can figure out how to assign the Text property on your own.
|
|
|
|
|
hi
How to print (and preview) any document - but not with CrystalReport
(working on VS2008 - C#)
ex. i have 6 val's in my C# program that i want to print (and preview)
how i can do it ?
thank's in advance
|
|
|
|
|
Printing is a rather complex matter. Printing a Form is based on the Paint handler and the PrintDocument class. My Sokoban article offers a simple example.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|