|
Good Day All
i have a unicode character which works very well
UnicodeString Thinking =0x1f914;
as you can see the value here is "0x1f914"
so i use this site which has a list of emoji's Full Emoji List, v12.0
but the code in that website is "U+1F914"
how do i convert U+1F914 to 0x1f914 in c#
thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
Directly? You can't. char is a UTF-16 value: is can't hold values higher than 0xFFFF because it only has space for 16 bits - your emoji value is 17. You are going to have to do a lot more than just convert it to hex, you will have to start playing with UTF32: UTF32Encoding Class (System.Text) | Microsoft Docs[^]
But to hex, or even an Int32 is simple:
string siteCode = "U+1F914";
int i = Convert.ToInt32(siteCode.Replace("U+", "0x"), 16);
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Good Day
After i looked closely on the string , with lack of knowledge of the unicode stuff , i realized i just needed to replace the character and the emoji will be translated , the code below simply solved the problem
<pre lang="c#">txtresults.Text = txttext.Text.Replace("U+", "0x").ToLower();</pre>
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
I have started a local host application and I attached a project in visual studio to this iexplorer process what was running the app. But I am unable to set break points in the code. I have tried to set break points but the errors says:
"This breakpoint will not currently be hit. No symbols have been loaded for this document."
Please advise.
|
|
|
|
|
|
The solution is to attach it to the w3wp process, not the iexplorer or any browser process.
|
|
|
|
|
ASP.NET, MVC, WebApi, ..., code always runs entirely on the server side, not in the browser. You're looking for your code in the wrong process.
|
|
|
|
|
The solution is to attach it to the w3wp process, not the iexplorer or any browser process.
|
|
|
|
|
I have a generic class with a complex signature that I would like to simplify for convenience if all of the type parameters will be the same.
MyClass<T1, T2, T3, T4>
If all of the type parameters are Guid, I'd like to supply just one type parameter, the only way I can think of doing it would be to have another class defined.
MyClass<T1> : MyClass<T1, T1, T1, T1>
Is there a better method of achieving this functionality? Is this a bad practice and should I just always use the verbose signature? Ultimately, I don't want there to be anything different between the classes other than the ability to use a simplified signature.
|
|
|
|
|
|
upvoted, and I mention you in my response here
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Failwyn wrote: Ultimately, I don't want there to be anything different between the classes other than the ability to use a simplified signature.
The answer depends on what you mean by that statement.
The derived class is the only solution I can see. But the types would not be exactly the same:
MyClass<Guid> a = new MyClass<Guid>();
MyClass<Guid, Guid, Guid, Guid> b = a;
MyClass<Guid> c = b; And:
MyClass<Guid, Guid, Guid, Guid> a = new MyClass<Guid, Guid, Guid, Guid>();
MyClass<Guid> b = (MyClass<Guid>)a;
MyClass<Guid> c = a as MyClass<Guid>;
Within a single file, you could use a using statement to create an alias for the type. But you can't use generic type parameters in the alias, so you'd need a different one for each set of type parameters you wanted to use:
using MyClassGuid = MyClass<Guid, Guid, Guid, Guid>;
...
MyClassGuid a = new MyClassGuid(); You'd also have to repeat the alias in each file where you needed to use it.
If it's constructing the objects you're worried about, then a factory method might help:
public static class MyClass
{
public static MyClass<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 value1, T2 value2, T3 value3, T4 value4)
{
return new MyClass<T1, T2, T3, T4>(value1, value2, value3, value4);
}
public static MyClass<T1, T1, T1, T1> Create<T1>(T1 value)
{
return new MyClass<T1, T1, T1, T1>(value, value, value, value);
}
}
...
MyClass<Guid, Guid, Guid, Guid> a = MyClass.Create(Guid.New());
MyClass<string, int, decimal, DateTime> b = MyClass.Create("Hello", 42, 123.45M, DateTime.Today);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Whoa !
Error CS0308 The non-generic type 'MyClass' cannot be used with type arguments
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Odd - it works fine for me:
Generic class factory | C# Online Compiler | .NET Fiddle[^]
using System;
public class Program
{
public static void Main()
{
Console.WriteLine(MyClass.Create(Guid.NewGuid()).GetType());
Console.WriteLine(MyClass.Create("Hello", 42, 123.45M, DateTime.Today).GetType());
}
}
public class MyClass<T1, T2, T3, T4>
{
public MyClass(T1 value1, T2 value2, T3 value3, T4 value4) { }
}
public static class MyClass
{
public static MyClass<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 value1, T2 value2, T3 value3, T4 value4)
{
return new MyClass<T1, T2, T3, T4>(value1, value2, value3, value4);
}
public static MyClass<T1, T1, T1, T1> Create<T1>(T1 value)
{
return new MyClass<T1, T1, T1, T1>(value, value, value, value);
}
} Output:
MyClass`4[System.Guid,System.Guid,System.Guid,System.Guid]
MyClass`4[System.String,System.Int32,System.Decimal,System.DateTime]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I see what happened: your first post did not include the non-static 'MyClass:
public class MyClass<T1, T2, T3, T4>
{
public MyClass(T1 value1, T2 value2, T3 value3, T4 value4) { }
} On the assumption that Richard Deeming never wrote code that was incomplete, or had errors, I thought I must be doing something terribly wrong
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
You know what they say about the word "assume"!
(I was assuming the generic classes described in the OP's post were already defined.)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This perceptual glitch of mine was simply the whine of a small dis-oriented horse-fly orbiting the radiance of your intellect
What interests me, much more, is whether you would agree that the attempt to "bend" the Generic canon here into a variable polymorphism ... is ... a complexity that costs more than its worth in terms of SOLID and future maintenance. That's what I said to the OP in my last post to him (albeit, in less fancy language/terms).Quote: imho, all of these implementations are hacks, and writing straightforward individual methods for each group of Types is better practice.
To me the attempt here to make these generic methods more "generalized" just leads to semantic confusion. It's not that much work to write a bunch of specific methods that can provide strict control over parameter validation, and can be unit tested efficiently. If there were ever a critical (unavoidable) need for this kind of facility: my wild guess would be to implement a factory that used Emit and CodeDom to build the classes.
cheers, Bill
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
BillWoodruff wrote: This perceptual glitch of mine was simply the whine of a small dis-oriented horse-fly orbiting the radiance of your intellect
BillWoodruff wrote: What interests me, much more, is whether you would agree that the attempt to "bend" the Generic canon here into a variable polymorphism ... is ... a complexity that costs more than its worth in terms of SOLID and future maintenance.
I guess it depends on the context. The question is fairly "generic" (no pun intended), so it's hard to see whether the generic type has any benefits over specific non-generic types in this case.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Please clarify whether you want to pass in a variable number of values in the 'ctor: if that's the case, this becomes a different problem.
If you are wiling to use 'params, as Gerry Schmitz suggests:
public class MyClass<T1, T2, T3, T4>
{
public T1 Value1 { get; }
public T2 Value2 { get; }
public T3 Value3 { get; }
public T4 Value4 { get; }
public MyClass(T1 value1, T2 value2, T3 value3, T4 value4)
{
Value1 = value1;
Value2 = value2;
Value3 = value3;
Value4 = value4;
}
}
public class MyClass<T1> : MyClass<T1, T1, T1, T1>
{
public MyClass(params T1[] values) : base(values[0], values[1], values[2], values[3])
{
}
} Note that if the number of parameters passed is less than 4, you'll get an index out of range error; I don't know of a way to intercept that error.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
modified 6-Apr-19 4:30am.
|
|
|
|
|
One knows how many parameters are passed based the count (values.Count) and can use defaults in the constructor, if need be.
Reflection can tell you what's being passed even when using all "objects".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: One knows how many parameters are passed based the count Not in this case; the indexing in the call to 'base is executed immediately during instantiation.
You could do it this way:
public class MyClass<T1, T2, T3, T4>
{
public T1 Value1 { get; set; }
public T2 Value2 { get; set; }
public T3 Value3 { get; set; }
public T4 Value4 { get; set; }
public MyClass(T1 value1, T2 value2, T3 value3, T4 value4)
{
Value1 = value1;
Value2 = value2;
Value3 = value3;
Value4 = value4;
}
protected MyClass()
{
}
}
public class MyClass<T1> : MyClass<T1, T1, T1, T1>
{
public MyClass(params T1[] values)
{
if(values.Length != 4) throw new ArgumentException("requires 4 parameters");
Value1 = values[0];
Value2 = values[1];
Value3 = values[2];
Value4 = values[3];
}
} But, look what happens: the Value properties in the base class now require a setter, and thw base class requirea a parameterless ctor.
imho, all of these implementations are hacks, and writing straightforward individual methods for each group of Types is better practice.
To me the attempt here to make these generic methods more "generalized" just leads to semantic confusion. It's not that much work to write a bunch of specific methods that can provide strict control over parameter validation, and can be unit tested efficiently.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
modified 6-Apr-19 18:55pm.
|
|
|
|
|
Gerry Schmitz wrote: Reflection can tell you what's being passed even when using all "objects". Why would you bring "reflection" into this ? Make the mess worse ?
Show me the code !
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
modified 7-Apr-19 6:57am.
|
|
|
|
|
Please consider my response to Schmitz here:
imho, all of these implementations are hacks, and writing straightforward individual methods for each group of Types is better practice.
To me the attempt here to make these generic methods more "generalized" just leads to semantic confusion. It's not that much work to write a bunch of specific methods that can provide strict control over parameter validation, and can be unit tested efficiently. Sometimes it's better not to be clever
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Using a step by step guild I created a "Engine" project in the solutions explorer and added classes to this "Engine project. In the main code I was able to refer to the "Engine" project by using "include Engine;. I noticed that when compiled C# had created a Engine.dll that contained all the classes.
I was wondering where the library of dll's are kept so I could add this engine.dll to the library to use in the future for some other code.
I'm pleased that you can create a lot of libraries to handle varibles and procedures which makes coding the main program much easier as you can use code such as '_player.CurtrentLocation.Description' and '_player.CurrentHitPoint' to refer to parts of the program within the DLL. Also there is no need for extra variables within the brackets, so this is possibles 'DisplayCurrentLocation()' making the code more tidier.
Brian
|
|
|
|
|
They are kept ... exactly where you put them!
When you create a solution, it creates a folder for it, and sub folders for each project in that solution - the source code is stored there, and the binaries in yet more subfolders.
The easiest way to find out exactly where a referenced library is is to open the "References" tab of your new project, and right click the reference. Select "Properties" and you will see the location under "Path".
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|