|
Lots of them but this looks like homework.
I imagine the Vector class is somewhere in your near future and use of the contains method.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
Hi,
this would be my attempt:
- strip all redundant characters from each string, probably every non-letter;
- optionally: normalize the casing, say convert all strings to lower-case;
- collect the strings in a List<string>, however before adding them, check whether the new string
is already present; if so you found a duplicate.
(you can improve on this by using a Dictionary which holds the string as a key, and the occurence
count as an int value).
BTW: why ask for an algorithm in a language oriented forum that does not match your language?
we do have a "Math and algorithms" forum.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:38 PM
|
|
|
|
|
Luc Pattyn wrote: BTW: why ask for an algorithm in a language oriented forum that does not match your language?
we do have a "Math and algorithms" forum.
Is not the forum called "Algorithms", I don't see "Math" there?
|
|
|
|
|
Ravadre wrote: Is not the forum called "Algorithms",
it has been called "Algorithms and Math", as well as "Math and algorithms" before.
However you are right, this week it is called "Algorithms".
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:38 PM
|
|
|
|
|
try using regular expressions....using remove method.. removing pattern[0-9]
the quieter u become more u hear
|
|
|
|
|
great idea lawrenceinba! but what do you mean with "removing the pattern"?
i'm not sure to understand this way..
Program your life ^^
|
|
|
|
|
Hi,
I am a developing an webcrawler in c#. The crawler will take a url from the user and crawls through the page pointed by that url fetching the urls it can find from the page.This is a recurring activity and the output is a huge collection of strings/urls.
Please tell me which is the best holder for such a huge data. I considered access database but it makes the application slow since reading and writing is a frequent activity.
Thanks,
John.
|
|
|
|
|
you could try a StreamWriter straight to a file
If only MySelf.Visible was more than just a getter...
|
|
|
|
|
Well, I'm about to pull my hair out on this. So I figured I'd post for help before I cause some premature baldness.
I'm fairly new to C# and have run into this problem trying to get info out of a int byte that I get returned.
Here is what is stated in the lib that I'm working with:
The first three bits represent a single value, not flags.
For example Auction (0x05) is not a combination of OwnedByOther (0x01) and ForSale(0x04). However, the BorderWest and BorderSouth values are bit flags that get attached to the value stored in the first three bits. Bits four, five, and six are unused.
public enum OverlayType : byte
{ Public = 0,
OwnedByOther = 1,
OwnedByGroup = 2,
OwnedBySelf = 3,
ForSale = 4,
Auction = 5,
BorderWest = 64,
BorderSouth = 128
}
So where I'm lost is trying to get the first 3 bits out and get the enum OverlayType from them. Plus the BoarderWest & BorderSouth.
|
|
|
|
|
Im a bit confused as to what you are trying to do?
If only MySelf.Visible was more than just a getter...
|
|
|
|
|
mask them
byte someByte ...;
byte masked = (someByte & 0xE) >> 2;
Don't trust my math on the bit shift though I was just guessing.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
Hello,
You would split your byte before checking for flags (borders) or values (<=5).
OverlayType value = (OverlayType)(type & 0x7); <br />
OverlayType flags = (OverlayType)(type & 0xC0);<br />
Or just do mask bits every time you need to check values from your byte. When checking for flags you don't care about lesser 3 bits, when checking for values, you just need to mask higher bits.
I'm not sure if I understand you well though, so I don't know if this is going to be any help.
|
|
|
|
|
ok, thanks. That's starting to make a bit of sence.
What I'm trying to do is check if it is Forsale and if so what are the BorderWest & BorderSouth.
the BorderWest & BorderSouth should each be a number. I got this working to identify what type it is. But now how do I get those boarder numbers?
modified on Tuesday, February 10, 2009 1:54 PM
|
|
|
|
|
the BorderWest & BorderSouth should each be a number. I got this working to identify what type it is. But now how do I get those boarder numbers?
In your example Borders are bit flags, so what do you mean by "border numbers"? They don't have a number, they are set or no.
|
|
|
|
|
hhmm, somewhere in there is a set of coordanants for the item. To locate it.
The summary part of that is:
"However, the BorderWest and BorderSouth values are bit flags that get attached to the value stored in the first three bits. Bits four, five, and six are unused"
That's what has been really confusing me. Trying to find those.
How can I just print out all the values in original int byte. Maybe just seeing whats in there I can locate the coords.
Thanks again for all your help.
|
|
|
|
|
Hello,
You are giving incomplete information or I can't understand your point.
You have a byte, that is what you have said. It has 2 bit flags (borderw, borders), which are set or not and some sort values, which I'm not sure what they do. Now your asking about getting sets of coordinates, without saying what they really are and from where you would like to get them. I'm confused .
|
|
|
|
|
I'm confused also. lol.
What this does is it sets a color on part of a grid based off of the type it is. So it's supposted to give the info for the type, to know what color to set. Then it's also supposted to hold the coords for where on the grid to set the color.
In part of the summary about the borders says "the BorderWest and BorderSouth values are bit flags that get attached to the value stored in the first three bits."
I assumed that ment that the coords are stored in the first three bits. The first part seems to be working correctly returning the correct type (Public, ForSale, etc). But with out the coords it doesn't help much.
I'm now trying to learn how to just view all the int values in the byte to try locate the coords.
|
|
|
|
|
First, you need to learn about the <pre> tag so you can post your code correctly.
Second, what you want to do is this:
[Flags]
public enum OverlayTypes
{ Public = 0,
OwnedByOther = 1,
OwnedByGroup = 2,
OwnedBySelf = 4,
ForSale = 8,
Auction = 16,
BorderWest = 32,
BorderSouth = 64
}
Then, you can do something like this:
OverlayTypes types = OverlayTypes.OwnedBySelf | OverlayTypes.ForSale | OverlayTypes.BorderWest;
if ((types & OverlayTypes.OwnedBySelf) == OverlayTypes.OwnedBySelf)
{
MessageBox.Show("Owned by self");
}
You could even do this:
OverlayTypes types = OverlayTypes.OwnedBySelf | OverlayTypes.ForSale | OverlayTypes.BorderWest;
OverlayTypes theseTypes = OverlayTypes.OwnedBySelf | OverlayTypes.BorderWest;
if ((types & theseTypes) == theseTypes)
{
MessageBox.Show("Owned by self, and borders west");
}
"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." - Jason Jystad, 10/26/2001
modified on Tuesday, February 10, 2009 4:25 PM
|
|
|
|
|
This is how you extract a range of bits from an integer value using a mask and bit shifting. If you understand this you can do anything!
Given the example number 179
10110011 number in binary
--+++---
00111000 mask to extract bits 3-5
00110000 intermediate result
00000110 final result
76543210 bit indices
The mask will extract the 3 bits marked with the +'s.
These are the 4 logical steps in the process
1) create a bit mask to cover the region of interest,
in this case 3 bits, binary 111 or hex 0x07
Byte mask = 0x07;
2) shift the mask into the correct position
In the example the mask starts at bit 3
Byte mask = 0x07 << 3; // mask is now binary 111000
3) Apply the mask to the number with the bitwise AND operation.
This allows the bits from the number to fall through
the mask into the intermediate result.
Int32 intermediateResult = number & mask;
or
Int32 intermediateResult = number & (0x07 << 3);
// the value is 110000
Note that when we do this the result is automatically widened to 32 bits.
4) Shift the intermediate result to the right to get the actual value
of the bits of interest.
Int32 result = intermediateResult >> 3;
or
Int32 result = (number & (0x07 << 3)) >> 3;
// result is binary 110 or 0x06 or decimal 6
As result was widened to 32 bits we can cast back to a byte if desired.
Take note of all the parentheses.
Byte result = (Byte)((number & (0x07 << 3)) >> 3);
If you want to see the result as a binary formatted string
String s = Convert.ToString(result, 2).PadLeft(8, '0');
// s is "00000110"
Here endeth the first lesson. Hope that helps a 'bit' and apologies for the pun.
Alan.
|
|
|
|
|
Hi Guys,
I am new to SharePoint, and fairly new to c#. I have done a lot of searching, and reading of articles on uploading files to SharePoint, but I haven't been able to get any of them to work because I either don't have the sharepoint.dll file, or the projects themselves seem to be missing parts so I haven't been able to look at any successful code. I apologize if this seems to be to be a repeat post/question, but I am a little frustrated so I am asking the question again in hopes to finding a definitive answer. Here is what I am looking to accomplish:
In it's simplest form, I am trying to write a C# application that will write some data to a file, and will then upload that file to a folder on our SharePoint site. I do not have Microsoft.SharePoint.dll on my computer, and the backup server that the program will be scheduled to run from will not have SharePoint installed on it, so it will also not have Microsoft.SharePoint.dll on it. I guess my question is, what is the best way to be able to accomplish this? Can I do it without copying the Microsoft.SharePoint.dll file from the SharePoint server? That seems like a hack way of doing it?? Is there an SDK that I should be installing to add/register that file to the server?? Some of the articles I have read talk about running it using asp.net on a web server, but I am looking to do it from a console application, so I don't think that applies??
I am running into dead ends on where to even start with this thing, so if anyone could give me at least an idea on where I should be beginning my research, it would be GREATLY appreciated!
Thanks in advance,
-Jeff
|
|
|
|
|
if you want to upload files to a server why not try using FTP
If only MySelf.Visible was more than just a getter...
|
|
|
|
|
Hi musefan,
Thanks your response. Unfortunately, it not as simple as just placing a file on the server. I need to upload the file into the SharePoint services which handles security, and attaches metadata to the file, along with some categorization functionality, file revisionining, etc.
-Jeff
|
|
|
|
|
I'm typically a PHP developer so this is a whole different realm to me. Is there a way I could toggle between network settings, for example if one machine is connected to a network where the IP address is automatically generated then connecting to a completely different network where the IP address has to manually entered, is there a way C# handles the TCP/IP settings to toggle between automatic and manual? If there is a way are there any resources out there I could read up on.
Thank you,
I apologize for the ambiguity.
|
|
|
|
|
Hey I have a StreamReader whose underlying stream is a NetworkStream, when I read from it, it throws a FormatException.
What could be the causes?
I am writing "r\r\n" to the NetworkStream and then call the StreamReader.ReadLine() method on the client side and it throws this exception.
What am I doing wrong?
|
|
|
|
|
You possibly got an incomplete packet of data? You possible only got a partial line of data from the network stream. Without seeing the code that handles this, it's impossible to say.
|
|
|
|
|