|
(Advanced) using LINQ...
PrintAreas( areas, parent, 1 );
static void PrintAreas( List<Area> areas, Area area, int indent ) {
Console.WriteLine( "".PadRight( indent++, '-' ) + area.Description );
areas.Where( a => a.ParentID == area.ID ).ToList()
.ForEach( each => PrintAreas( areas, each, indent ) );
}
|
|
|
|
|
Hallo I have this code
<form ng-submit="onSubmit()" class="ng-pristine ng-valid ng-valid-maxlength">
<input type="text" maxlength="100" class="searchboxfield ng-pristine ng-untouched ng-valid ng-valid-maxlength" name="searchboxfield" data-test="searchboxfield" ng-model="model.term" ng-change="model.submit=false" placeholder="Zoek op EAN, titel of referentiecode">
</form>
How can I click programaticliy on c#
|
|
|
|
|
You can't programmatically click buttons from server-code, you'll have to do it from javascript\jquery.
|
|
|
|
|
I'm trying to uppercase the second word in a string of two words (a first and last name).
int index;
string name = "Jeffrey steinberg";
index = name.IndexOf(' ');
name = name[index + 1].ToUpper();
The toupper function isn't working though. How would I uppercase just the s in steinberg?
|
|
|
|
|
Here's the method I use:
private void butLowerCase_Click(object sender, EventArgs e)
{
bool sentenceCase = (ModifierKeys & Keys.Control) != Keys.Control;
if (Clipboard.ContainsText())
{
string s = Clipboard.GetText();
string[] lines = s.Split('\n');
StringBuilder sb = new StringBuilder();
string EOL = "";
for (int i = 0; i < lines.Length; i++)
{
sb.Append(EOL);
if (lines[i].Length > 1)
{
if (sentenceCase)
{
sb.Append(lines[i].Substring(0, 1).ToUpper());
sb.Append(lines[i].Substring(1).ToLower());
}
else
{
string[] words = lines[i].ToLower().Split(' ');
string sep = "";
foreach (string word in words)
{
if (word.Length > 0)
{
if (conjunctions.Contains(word))
{
sb.AppendFormat("{0}{1}", sep, word);
}
else
{
sb.AppendFormat("{0}{1}{2}", sep, word.Substring(0, 1).ToUpper(), word.Length > 1 ? word.Substring(1).ToLower() : "");
}
sep = " ";
}
}
}
}
else
{
sb.Append(lines[i]);
}
EOL = "\n";
}
Clipboard.SetText(sb.ToString());
}
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I also have something similar, except along with conjunctions, I skip articles and prepositions as well.
You have just been Sharapova'd.
|
|
|
|
|
Console.WriteLine( System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase( "Jeffrey steinberg" ) );
|
|
|
|
|
|
I am just learning C# and would like code to loop all pages in a Microsoft Word 2010 document and find if a string exists in the page header, body, and footer and print the results to a text file.
Example: Find if a certain date is in the header, body, and footer of each page of the Microsoft Word 2010 document. If the date is not found on page 5, then print date is not in the header of page 5.
|
|
|
|
|
What have you tried?
/ravi
|
|
|
|
|
I found this code for a word count, but I want to loop pages and search the header, body, and footer.
using System;
using Microsoft.Office.Interop.Word;
class Program
{
static void Main()
{
// Open a doc file.
Application application = new Application();
Document document = application.Documents.Open("C:\\word.doc");
// Loop through all words in the document.
int count = document.Words.Count;
for (int i = 1; i <= count; i++)
{
// Write the word.
string text = document.Words[i].Text;
Console.WriteLine("Word {0} = {1}", i, text);
}
// Close word.
application.Quit();
}
}
|
|
|
|
|
|
Hi I'm new to programming and I'm still confused most of the times to figure out the logic behind those problems that I'm working with. I feel like I'm so stupid. I wonder how other programmers come up to those kinds of solutions. Please give me some tips on how to improve my programming skills.
|
|
|
|
|
Everyone here was once a "beginner;" don't feel alone
Suggestions:
1. decide on an initial language to learn: I recommend C# used in the context of the .NET framework.
2. get a good book on the language you've chosen to learn, and get a programming environment (IDE) set up where you can start experimenting with the language. I recommend using the free editions of Visual Studio for your IDE. For a book: how about Charles Petzold's ".NET Book Zero," which is free: [^].
3. Start studying, start experimenting, download the code samples (if available) in the book you are using, run them, and experiment with them.
4. very important: learn how to debug ... to set break-points, to observe the value of variables, and the "state" of "objects."
5. get so busy learning, experimenting, and analyzing the results of your experiments, that you never have time to think about whether or not you are a "beginner," or, if you "understand programming."
cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
It's not too bad, once you get your head around the process.
Start by breaking the task into smaller chunks - for example, it your have to get two values from the user, add them together and print the result (and yes, I know it's trivial) then you would brak it into three bits:
1) Get values
2) Add
3) Print Then look at the first one "Get values" and break that into smaller bits:
1) Get values
1.1) Get a value
1.2) Store it somewhere
1.3) Get a value
1.4) Store it somewhere else
2) Add
3) Print And you start to see that 1.1 and 1.3 are the same job - so they can be done with the same code. You then continue this until each of the tasks you have is pretty simple - and then implement them!
There is a technical term for this - reductionism - and it's a process we use all the time in real life without really realising it: "Make tea" for example reduces to "boil water", "brew tea", "add milk and sugar", "combine" - and each of those breaks down into simpler actions we take without thinking.
Another way to get started is to do the job manually, and think about the processes you are involved in to do it. This can give you a good idea of the overview, and you can then start reductionism to separate out the simpler tasks.
It's a skill - and like all skills it only comes with practice - so try it. You'll get it wrong (we all did, and we all do) so be prepared to throw it away and start again, but you'll get better as you go along.
Good luck!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
These days, the main emphasis seems to be on the "newer" analysis and design tools: state diagrams; sequence diagrams; activity diagrams; etc.
I don't think any of these tools is a substitute for a plain "old" flowchart and / or decision tree when it comes to a particular piece of non-trivial logic.
A simple flowchart can help one to better understand a particular process (and how to program it).
If you're not familiar with flowcharts or decision trees (or some of the other "older" tools), you should take the time to learn about them if you are serious about programming. Even the "old" stuff can be useful in a particular situation.
|
|
|
|
|
Hi Gary,
I find your mention of "decision trees" very interesting; I have always wondered why they seem to have been "left-behind" in the last years.
I've been implementing my own decision-tree control in C#/.NET and intent to publish it here when it's "ripe."
An intellectual problem I see in implementing useful decision trees is to figure out a way to analyze the possibly numerous criteria so that you select-out the variables whose state-change has the maximum predictive power for the outcomes.
Imagine an air-fare discount decision-tree with some thirty possible variables, each having #n possible states: analysis of the possible decision matrix might lead to concluding that the most "powerful" predictive variable was the flyer's "age."
How to create an interface that assists "mere mortals" to write efficient decision-tables that are "pruned" so that the minimal effective set of rules/actions are used. That's the interesting problem, to me.
cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
the problem is only a problem as loong as u dont have the solution yet;)
"Divide and conquer". Break Down the problem so much Down that u only solve 1 problem at the time.
If u have to do that solution many times, look for "loops".
But i think that every programmer has his weak points.
But u will get stronger and stronger to see what to do.
Using a editor will give u some sort of feedback, to what u are missing.
And mistacks will be made , i dont think i ever 1 shottet a solution. Allways something Little thing that i overlook.
I my self find web programming slow, so slow that i have to only do 2-3 linie before i debug. Mayby because of ininspirence but havnt find a editor for it. It just Work or it dosnt.
And it is easy just to look and twist a few linies to see the result, than to look at 15 linie, and no where to start.
So just keep learning.
It is mostly just matematik and logik.
And speeking of logic, i still get - less than and greater than (<>)the wrong way.
Best regards
jan
|
|
|
|
|
Hello,I understand Shell Sort definition but I can not understand
this C# code:
public void shellSort()
{
int inner, outer;
long temp;
int h = 1;
while(h <= nElems/3)
h = h*3 + 1;
while(h>0)
{
for(outer=h; outer<nElems; outer++)
{
temp = theArray[outer];
inner = outer;
while(inner > h-1 && theArray[inner-h] >= temp)
{
theArray[inner] = theArray[inner-h];
inner -= h;
}
theArray[inner] = temp;
}
h = (h-1) / 3;
}
}
please help me thx!
modified 2-Oct-15 4:39am.
|
|
|
|
|
The best way for you to help yourself understand this code is to create the initial Array and the required 'nElem variable, put a break-point at the start of the code, and then run the program, single-stepping (using F11 in Visual Studio) through the code, and observing what happens with each step. Hover the mouse over the variables and inspect their current values.
As you study what is happening in the code, take breaks, and go back and read about how the Shell sort "works." Then observe/study the running code again.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
The answer hasn't changed since you posted exactly the same message[^] yesterday.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Message Removed
modified 2-Oct-15 4:40am.
|
|
|
|
|
I have a table in a database containing a number of records. The records have an ID number i.e. H1, H2, H3. Each record also contains a field called C1 which contains a value.
There can be multiple records with the same ID.
I want to read all the values of fields C1 for records with the ID H1 into an array. I don't know exactly how many records there are with the ID H1.
I don't want to do this in SQL.
Does anyone know how I would create a collection holding the values?
|
|
|
|
|
Read the data from the Db using a trivial SELECT:
SELECT C1 FROM MyTable WHERE ID='H1'
You can read the values using a DataReader, or a DataAdapter - whichever you are comfortable with.
For a reader, it's really simple:
List<MyTypeOfData> collection = new List<MyTypeOfData>();
while (myReader.Read())
{
collection.Add((MyTypeOfData) myReader["C1"]);
}
For an adapter, just use the table data in a Linq query:
var collection = myDataTable.AsEnumerable().Select(row => (MyTypeOfData) row["C1"]);
[edit]forgot the brackets... [/edit]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks for the reply OriginalGriff.
What i want to do is add together all the values for each occurence of C1 and then to write this to a field.
Can I do this with what you have suggested?
|
|
|
|