|
Took me less than a minute to see that:
pair.ToString()
returns the key and value surrounded by square brackets:
KeyValuePair<string, string> foo = new KeyValuePair<string, string>("foo", "bar");
Console.WriteLine(foo.ToString());
Output:
[foo, bar]
|
|
|
|
|
Yeah, you're right.
Is there any way to avoid that or remove it?
|
|
|
|
|
Good spot, @Richard_MacCutchan!
How about changing
string[] my_arr = pair.ToString().Split(',');
my_table_code.Rows.Add(my_arr[0], my_arr[1], my_arr[2]); to
string[] my_arr = pair.Value.Split(',');
my_table_code.Rows.Add(pair.Key, my_arr[0], my_arr[1]); ?
Note: This is off the top of my head, not tested. Caveat Emptor.
modified 20-May-21 6:05am.
|
|
|
|
|
|
[] is the C# syntax for indexing: it's used with a numeric value for ordered Collections, and other types of values with Collections like Dictionary<TKey, TValue> that have no inherent ordinality.
That's just the way the language is.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Hi,
i would to make an explorer to add some methods i need behind. I tried a lot of things but many are deprecated. I'm under windows 10 x64. I want to make my app under .net core.
I tried SHGetSpecialFolderLocation but the name i retrieve is in chinese... i don't understand why. I saw with windows 10 it's better to use knownfolderid but i search in my registrykeys and i didn't find mega key, but it uses a clsid. Should it a good idea to ask to the registry or is there another method ?
i want to make something classic, with "mycomputer" root, make drives under it (it's ok for this part), have clouds folder also... And i will try to get default icons, i have some methods using win32.dll (if you have better i will happy to have more informations).
|
|
|
|
|
You haven't explained any kind of problem you're having.
I'm going to guess that you're trying to use SHGetSpecialFolder location to get the paths to cloud folder. That will not work as they are not part of the Windows file system.
AFAIK, there is no standard method to get cloud folder paths. You'd have to write support modules for each cloud provider you want to support and ask the user for their username and password to get into those folders.
|
|
|
|
|
hi, thanks for your answer.
I tried several things, even before i tried to read sources from this example
I used
IntPtr m_pIDL = IntPtr.Zero;
hRes = ShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.CSIDL_DESKTOP, ref m_pIDL); but it's deprecated, so i used
hRes = ShellAPI.SHGetFolderLocation(IntPtr.Zero, 0, IntPtr.Zero,0, out m_pIDL);
For retrieve informations i used
SHFILEINFO shInfo = new SHFILEINFO();
ShellAPI.SHGetFileInfo(m_pIDL, 0, out shInfo, (uint)Marshal.SizeOf(shInfo),
SHGFI.DisplayName |
SHGFI.PIDL |
SHGFI.SmallIcon |
SHGFI.SystemIconIndex
);
But i get
畂敲畡 as display name, and 34 as iIcon in all cases. Which means "toc toc" (knocking) according to google translate.
I can't go more forward, i'm totally blind because of that.
This example is interesting because it give me what i need, i have one drive & mega folders and it seems there is no special instruction to have it, it lists elements by using
EnumObjects
This is why i would to use some elements under .net core and learn how to use windows api, instead of using c# with methods from Directory. If i understand well it's a handle (pointeur?).
SHFILEINFO
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
}
[DllImport("shell32.dll")]
public static extern int SHGetFolderLocation(IntPtr hwndOwner, int csidl, IntPtr hToken, uint dwReserved, out IntPtr ppidl);
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SHGetFileInfo(string path, uint attributes, out SHFILEINFO fileInfo, uint size, uint flags);
[DllImport("shell32.dll")]
public static extern IntPtr SHGetFileInfo(IntPtr pIDL, uint dwFileAttributes, out SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
#endregion
modified 19-May-21 20:13pm.
|
|
|
|
|
What's the return value from your SHGetFileInfo call. If it's 0, then some error occurred and you're going to have to use GetLastError to get the error code to see what happened.
|
|
|
|
|
Hi, i have an hexadecimal value for the return value.
I ask myself if i must continue to this way, i read somewhere else it was an old way to do it like a c++ copy/paste. I would to have something quick, with all default icons (i don't know another way for folders than to use win32.dll this is why i thought about make all with api methods)
Meanwhile, to go forward i found a way to get mega folders, i post here if it can help others.
var identity = System.Security.Principal.WindowsIdentity.GetCurrent();
string userName = identity.Name.ToString();
string userSID = identity.User.ToString();
List<string> MegaFolderPaths = new List<string>();
RegistryKey clsidKey = Registry.Users.OpenSubKey($"{userSID}\\Software\\Classes\\CLSID");
foreach (string subKey in clsidKey.GetSubKeyNames())
{
RegistryKey clsidSubKey = Registry.Users.OpenSubKey($"{userSID}\\Software\\Classes\\CLSID\\{subKey}\\Instance\\InitPropertyBag");
if (clsidSubKey == null)
continue;
string defaultValue = (string)clsidSubKey.GetValue("TargetFolderPath");
if (!string.IsNullOrEmpty(defaultValue))
MegaFolderPaths.Add(defaultValue);
}
-------------------
Edit: for the chinese character i didn't see i forgot to add this
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
above
public static extern Int32 SHGetFileInfo(IntPtr pIDL, uint dwFileAttributes,
out SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
modified 21-May-21 3:29am.
|
|
|
|
|
(beginner question)
I have a small app and a Class Library that generate a DLL and an EXE.
I read that I can use ILMerge to merge the DLL and EXE together.
The NuGet says the package is deprecated:
"This package has been deprecated as it is legacy and no longer maintained"
Is there something newer or another way to do this, merge the DLL and EXE ?
Thanks.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
|
I am trying to replace a text with something. most often it works but for a particular text replace not working. here is the code example.
string maindata = "Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
string data = "Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
string strformula = Regex.Replace(maindata, "\"" + data.Replace("(", "\\(").Replace(")", "\\)").Replace("$", "\\$") + "\"", "W51",RegexOptions.IgnoreCase);
strformula = maindata.Replace("\"" + data.Replace("(", "\\(").Replace(")", "\\)").Replace("$", "\\$") + "\"", "W51");
i tried both Regex.Replace() & String.Replace() but no luck. what is so special in the text "Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999" for which replace not working ?
please give me some direction. thanks
|
|
|
|
|
It might help if you could give some before and after examples, from what I can see nothing would change from the test data provided.
Do yourself a favour and don't chain the replace statements like that as it makes it difficult to see what is going on and almost impossible to debug and is a maintenance nightmare and is neither clever or helpful.
Split the whole line into discrete steps so you can examine what the before and after values are at each replace step.
|
|
|
|
|
Here i am posting simple replace. please run at your side then understand Replace() not able to replace.
string maindata = "Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
string data = "Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
string strformula = Regex.Replace(maindata, data , "W51",RegexOptions.None);
try my above code and must notice replace not able to replace Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999 with W51
Thanks
|
|
|
|
|
You need to escape the unescaped + character in your data string.
|
|
|
|
|
This code solve my issue. thanks a lot for your reply.
string maindata = @"Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
string data = @"Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
data = Regex.Escape(data);
string strformula = Regex.Replace("\"" + maindata + "\"", "\"" + data.Replace("(", "\\(").Replace(")", "\\)").Replace("$", "\\$") + "\"", "W51", RegexOptions.None);
|
|
|
|
|
Regexes can get quite complicated, and many characters are "special" - they tell the expression engine to do something specific.
'+' is one of them: it means "One or more of the previous item":
^A\d+B$ Will match an 'A' followed by any number of digits other than zero, then a 'B'.
If you need to use a "special character" as a literal charcater, you need to escpae it by prefixing it with a backslash:
^A\d\+B$ Will match an 'A' followed by a single of digit, then a '+', then a 'B'.
A1+B will match, A12B will not.
If you are going to use regexes, the get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
It'll help you a lot!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This code solve my issue. thanks a lot for your reply.
string maindata = @"Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
string data = @"Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
data = Regex.Escape(data);
string strformula = Regex.Replace("\"" + maindata + "\"", "\"" + data.Replace("(", "\\(").Replace(")", "\\)").Replace("$", "\\$") + "\"", "W51", RegexOptions.None);
|
|
|
|
|
It's fun to chain .Replace but it keeps you from knowing what's happening from one to the next.
It's not any faster than using the occasional intermediate variable.
If you chain that many, at least put them on a separate line.
string strformula = Regex.Replace(maindata, "\"" + data
.Replace("(", "\\(")
.Replace(")", "\\)")
.Replace("$", "\\$") + "\"", "W51",RegexOptions.IgnoreCase);
Then it should also be obvious that "data" should have it's own statement.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi, folks.
I'm programing in C# in Visual Studio 11. I changed a form font to bold (unique change) but as I didn't like the efect, I tried to return the form to regular text, but VS didn't return the form to regular font, no matter what. I noticed it's impossible to go back. Does anyone know how to do this? What am I doing wrong?
Thanks.
|
|
|
|
|
How did you change it, and how did you try to reset it?
|
|
|
|
|
Snap!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi, Richard.
I changed the font in the Properties Tab.
Do you have any idea?
Thanks.
|
|
|
|
|
Ismael Oliveira 2021 wrote: Do you have any idea? Sorry, no. Without more details we cannot even make a guess.
|
|
|
|
|