|
Select only the field containing the data that you want, and use the distinct keyword to get only one of each value.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
I'm trying to write as a small project a custom file explorer in C# however I've hit a rather annoying problem... When a file is > 260 characters long (yeah, I know people shouldn't have files that long, but they do) it'll throw the PathTooLongException fine, but what do you do next?
I was hoping I'd be able to catch that exception and at the same time still get the file size and other information I need to display but no such luck.
Is there any work-around's to fix this, or would the only acceptable solution be to write a custom library that properly wraps the Win32 API functions which are able to get the sizes/other information of > 260 char files? If so does anyone know an open-source library already made to do this, or will I need to make one?
Thanks!
|
|
|
|
|
I'm able to set unsafe mode in a console application by checking the checkbox in "Project Properties -> Build -> Allow unsafe code" however that option isn't available in a web service project.
So how can I set a web service project to unsafe mode?
Thanks.
-Goalie35
|
|
|
|
|
Is there a simple way to parse a string that contains escape character to the appropriate string, and vise versa?
For example, given the following string:
"hello\tthere"
should be parsed to:
"hello there"
and vs.
I need these methods because i let the user to enter escape chracters within the strings.
Thnaks!
|
|
|
|
|
*simple* solution....as you asked. If you know every one of your escape characters (say you only use 2 for illustrative purposes... '/t' and '/n') you can add each one of them to a string array. Then whenever you need to parse your input string, call inputString.Split(delimiterList) where delimiterList is your array of characters. That parses your text as you requested, but I don't think you really want what you asked. ...If you allow users to insert escape characters, why would you want to eliminate them whenever you parse the input string? I think what you are actually asking is for an algorithm to perform character substitution for a particular escape sequence. Am I right?
|
|
|
|
|
Escape characters are in your text when you enter the constant, but in the string itself, they become ( for example ) tabs and so on.
If you have a string which actually contains the \t, etc, then you need to use string.Replace to remove them, if that's what you need.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Please give a more illustrative example of what you are trying to accomplish. Are you saying that '\t' is supposed to represent a single whitespace character? In the original reply that I made, I assumed that 'hello' and 'there' were 2 seperate tokens created from parsing a string with a given delimiter. I think you really meant that you want to traverse the string and perform a character substitution based upon your defined escape sequences.
|
|
|
|
|
Hello
This is what you need:
string s1 = "hello\tthere".Replace("\\t", "\t");
string s2 = "hello\tthere".Replace("\t", "\\t");
Andriy Zhornyk, regards
|
|
|
|
|
The idea is to enable the user to enter string constants that contains escape character - eaxactly as we do when we edit our source code in VS.
For example, the user maybe enter the following text in some text box:
"Hello\there\nand\there. But \\this is a backslash and not a tab chracater"
So, when i get this string, .NET framework treats these sequences as is and not as escape character - this is the expected behavior.
If you add a breakpoint at the right point and watch this user input in the debugger you will see:
"Hello\\there\\nand\\there. But \\\\this is a backslash and not a tab chracater"
However, i was wondering if there is a simple way, that is method supplied by the framework that do the job of escape character substitution as well as the reverse job.
So when i get this string i do the following:
string result = SubstituteEscapes(userInput);
...and the result will contains the same string after the "\t" replaced by the tab character and the "\n" replaced by the new line character and the
"\\" will be replaced by a single "\".
and the reverse way should be:
string original = SubstituteSpecialCharacters(result);
...and the the tab, new line and backslash characters will be replaced with the appropriate escape sequences.
It is possible to search and replace those escapes even by using regualr expressions. But does the framework has a built in method for that?
Why?
You may ask your self why i need these methods?
Well i use a ProperttyGrid and ask the user what should be the seperator string between fields in the log file.
Beacause pressing tab move the focus to the next property in the grid, and also because copying and pasting tab is BAD solution to this problem, i want to give the user the possiblity to enter escapes.
Thanks, again!
|
|
|
|
|
Your users are sufficiently technical to understand the concept ?
So you actually want to parse for \t and replace it with a tab ? I imagine you need to use the string.Replace method to do this for all known special characters, including replacing \\ with \
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Well, they are.
However it seems up to this point that there is no such built in method, hence i am writing such method now.
The principle is a little more complicated than seraching and replacing, consider the \uxxxx unicode escapes, \xd[d][d][d] hexadecimal escapes (variable length up to 4 digits) etc.
At the moment i finish this method (soon) i post it.
|
|
|
|
|
First, thank you all for trying to help me, as i said, it seems that there is no built in method for escape sequences substitution.
Hence i set down and wrote the following method, hopefully with no bugs.
In the method i use scanning instead of serching and replacing as well as some bitwise operations in order to enhance performance.
The reverse method is much simpler to code.
Finally, here in Israel we celebrate a new year - so happy new year to you all.
Here is the method.
/// <summary>
/// Substitutes the escape characters in the specified string with their appropriate characters.
/// </summary>
/// <param name="str">The string.</param>
/// <returns>The string after the escape characters were replaced by the appropriate character.</returns>
/// <remarks>
/// If the method encounter invalid escape character, the backslash character is removed and
/// the character that comes right after it is copied with no change.
/// </remarks>
public static string SubstituteEscapes(string str)
{
StringBuilder sbResult = new StringBuilder();
bool bEscaped = false;
for(int i = 0; i < str.Length; i++)
{
char current = str[i];
if(bEscaped)
{
switch(current)
{
case '\'':
case '\"':
case '\\':
/* Merely append the current character. This is the default behavior */
sbResult.Append(current);
break;
case '0':
/* The '\0' (string terminator) character \u0000 */
sbResult.Append('\0');
break;
case 'a':
/* The bell (alarm) character \u0007*/
sbResult.Append('\a');
break;
case 'b':
/* The backspace character \u0008*/
sbResult.Append('\b');
break;
case 'f':
/* The form feed character \u000C*/
sbResult.Append('\f');
break;
case 'n':
/* The line feed character \u000A*/
sbResult.Append('\n');
break;
case 'r':
/* The carriage return character \u000D*/
sbResult.Append('\r');
break;
case 't':
/* The tab character \u0009*/
sbResult.Append('\t');
break;
case 'v':
/* The vertical tab character \u000B*/
sbResult.Append('\v');
break;
case 'u':
/* Unicode character (exactly four digits to read on) */
try
{
char ch = (char)int.Parse(str.Substring(i + 1, 4), NumberStyles.AllowHexSpecifier);
sbResult.Append(ch);
i += 4;
}
catch
{
sbResult.Append(current);
}
break;
case 'x':
/* hexadecimal (1 digit up to 4 digits to read on) */
int j = 0; /* cout how many digit were scanned */
int value = 0; /* hold the value */
do
{
try
{
int curr = int.Parse(str[i + j + 1].ToString(), NumberStyles.AllowHexSpecifier);
value = ((value << 4) | curr);
j++;
}
catch
{
break;
}
} while(j < 4);
if(j != 0)
{
sbResult.Append((char)value);
i += j;
}
else
{
sbResult.Append(current);
}
break;
default:
/* Unrecognized escape chracter */
sbResult.Append(current);
break;
}
bEscaped = false;
}
else
{
if(current == '\\')
{
bEscaped = true;
}
else
{
sbResult.Append(current);
}
}
}
return sbResult.ToString();
}
|
|
|
|
|
string WildCardPatern.UnEscape(string pattern)
"Converts a string that has escaped characters to a string that includes the escaped characters in their unescaped form. "
I've never tried it, but the description sounds like exactly what you want...
Ooops, looks like that's only available in .Net 3.0 (Winfx) - System.Management.Automation namespace ...
|
|
|
|
|
After wasting some time writing the method, Rob Graham give me a clue.
Rob Graham, you are right this method is in .NET 3.0, but there is another method with the same name:
Regex.Unescape
This function do the job.
BUT, this method is not error tolerant like my method;P.
So, if someone meant to use unescape and want to skip invalid escape sequences - my method does it.
Rob Graham - Thank you, again!
|
|
|
|
|
hi im trying to bind a listbox to a datasource unsuccesfully, this is my code
DataTable myDt=...somefunction that returns a datatable with one row
myListbox.datasource=myDt.rows[0]
how can I databind without having to use the popolating while cycle?
thank you
|
|
|
|
|
this.lstFieldPool.DataSource=myDS.Tables[0];
this.lstFieldPool.DataTextField="name";
this.lstFieldPool.DataBind();
now it works
|
|
|
|
|
Hi,
When there were no .NET, Visual Basic or Visual C++ was the choice for .NET programming (and also Delphi). I am comfortable with C++ style coding like C# or Java etc, not Visual Basic or Delphi..
Now, what is best choice in these days for making very light weight native windows executables which doesn't require any .NET framework ? If I make a C# program, can I convert that to simple light weight native program using any tool ?
Thanks
|
|
|
|
|
Hello
There's no tool for conversion .NET application to Win32 application. Use C++ or Delphi 7 (or lower). Have a luck.
Andriy Zhornyk
|
|
|
|
|
The same as it always was - C++. C# and VB.NET require the framework, that's all there is to it. You can't convert a C# app to c++, no.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello
bashiwala wrote: Now, what is best choice in these days for making very light weight native windows executables which doesn't require any .NET framework ?
Well, C++ of course!! in C++ you can make API calls that will run on any Windows edition.
bashiwala wrote: can I convert that to simple light weight native program using any tool ?
Check Xenocode Postbuild[^]
Regards
|
|
|
|
|
hi
im working on an application P2P file sharing (like eDonkey) and instant messaging.
what tecnologies should i use? Web Services, RPC, XML or something like that.
i know C++ and Delphi and Multithreaded, Socket programming but im new at C# and Microsoft .NET technologies.
please help me, really i don't know where to start!
thank you.
asamay
|
|
|
|
|
You might want to put your knowledge into developing a C++/CLI application then. It's C++ with .NET.
ROFLOLMFAO
|
|
|
|
|
Hello
Even P2P programs need servers to organize all those peers. Make a Socket application that would act as a listner server to accept peers and synchronize between them. Then make you client app that would get the ips of other peers from that server, then directly contact those peers by ip. System.Net.Sockets namespacce has all that you need.
Regards
|
|
|
|
|
thanks, its not a pure P2P application as u told, there is a discovery server for authorizing and locating sharing file list and some permissions about them.
i found an article about P2P programming with .NET technologies,
here it is
http://msdn.microsoft.com/msdnmag/issues/01/02/netpeers/default.aspx
it will be very useful for developing P2P app with .NET
thanks again.
asamay
|
|
|
|
|
Obviously I'm doing something wrong, or typed datasets are the most worthless invention ever because they never work.
1). I constantly get Original_ appended to parameters. Why would I ever need an update to look like this: Update(string title, string otherData, int Original_id, int id) when the id column is a PK and an identity column?
2). "...could not find a non-generic method 'Update' that has parameters:...". So, if just let the DS make all its own methods, then create a new ObjectDataSource with this DataSet as its DataObject the Update method VS generated BY ITSELF is not good enough?! Whats the point of it automatically generating the Insert, Update, and Delete methods if you need to write all sorts of code just for them to work properly?
I got tired of having to write a sort and paging method for every stupid GridView in the project, but its way easier than this.
|
|
|
|