How To Create Emoji Strings From Unicode Value? [duplicate] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to convert emoji's like the one below to c# code so I can put the code in a TreeView node or facebook or other social engine. I tried the code for airplane and shows a little airplane in the treenode. But I use another airplace code like U+1F6E9 it just shows a little rectangle not the emoji. Please help.
string tnt = "Airplane " + char.ConvertFromUtf32(int.Parse("U+2708".Substring(2), System.Globalization.NumberStyles.HexNumber));
MyTreeView.Nodes.Add(tnt);

Here is a class you may use to implement different emoji's in your application.
public class Emoji
{
readonly int[] codes;
public Emoji(int[] codes)
{
this.codes = codes;
}
public Emoji(int code)
{
codes = new int[] { code };
}
public override string ToString()
{
if (codes == null)
return string.Empty;
var sb = new StringBuilder(codes.Length);
foreach (var code in codes)
sb.Append(Char.ConvertFromUtf32(code));
return sb.ToString();
}
}
I would use the codes from this site unicode.org
Instead of using the code it has on the site which is something like 'U+1F366' I would use '0x1F366' to specify hexadecimal notation. Hope this helps.

Related

How To Translate Unicode Value To Emoji String in C#? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to convert emoji's like the one below to c# code so I can put the code in a TreeView node or facebook or other social engine. I tried the code for airplane and shows a little airplane in the treenode. But I use another airplace code like U+1F6E9 it just shows a little rectangle not the emoji. Please help.
string tnt = "Airplane " + char.ConvertFromUtf32(int.Parse("U+2708".Substring(2), System.Globalization.NumberStyles.HexNumber));
MyTreeView.Nodes.Add(tnt);
Here is a class you may use to implement different emoji's in your application.
public class Emoji
{
readonly int[] codes;
public Emoji(int[] codes)
{
this.codes = codes;
}
public Emoji(int code)
{
codes = new int[] { code };
}
public override string ToString()
{
if (codes == null)
return string.Empty;
var sb = new StringBuilder(codes.Length);
foreach (var code in codes)
sb.Append(Char.ConvertFromUtf32(code));
return sb.ToString();
}
}
I would use the codes from this site unicode.org
Instead of using the code it has on the site which is something like 'U+1F366' I would use '0x1F366' to specify hexadecimal notation. Hope this helps.

Text Contains two different strings? WebDriver C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying to assert whether two or more strings are evident. My code currently only looks for "Good". Is there a way to look for "Good" or "Bad"?
public class Test
{
public static bool FindText()
{
var conf = Driver.Instance.FindElement(By.Id("foo"));
if (conf.Text.Contains("Good"))
{
return true;
}
throw new Exception("Text not found");
}
}
I would use System.Linq and check against all elements of an array, if there could possibly be more than two valid strings.
public class Test
{
public static bool FindText()
{
var stringsToFind = new [] { "Good", "Bad" };
var conf = Driver.Instance.FindElement(By.Id("foo"));
if (stringsToFind.Any(s => conf.Text.Contains(s))
{
return true;
}
throw new Exception("Text not found");
}
}
for only two elements to check I would propably just extend the if condition with a second condition and an or.
When trying to find a string, always make the string variable to upper or lower case. Since it's case sensitive, when the text is "GoOd", you won't find a match looking for "Good"
if(conf.Text.ToUpper().Contains("GOOD")){
//do something
}
else if(conf.Text.ToUpper().Contains("BAD")){
//do something else
}
You could also put then in only one "if" statement, if you're only interested in finding out if there's any of those by using
if(conf.Text.ToUpper().Contains("GOOD") || conf.Text.ToUpper().Contains("BAD")){
//do something for both cases
}
|| is the operator for the OR operation
if (conf.Text.Contains("Good") || conf.Text.Contains("Bad"))
PD : Stop whatever you are doing and take a look to the language docs, you need to understand what are you doing.

Parse Json string and sort based on property in C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am working on a window app in which a json string like
{
"0":{"UID":"3182713a-60de-4576-ad82-6804d2acf2b7","Rating":-1},
"1":{"UID":"eb41478e-e9bc-428e-8203-482f6a329666","Rating":-13},
"2":{"UID":"a0922817-e706-4478-8995-d258bada488d","Rating":6.0033992049},
"3":{"UID":"e0716752-56f4-49af-a811-ae55c69baa3d","Rating":-4.9836395671},
"4":{"UID":"ec6bf376-17b5-4a9e-92be-990557551cd0","Rating":-7.754526396}
}
I want to parse and sort it by rating. Please suggest how i can achieve it.
You will need to deseralise the JSON into a Dictionary<int, YourClass>
Example:
var json = #"{
""0"":{""UID"":""3182713a-60de-4576-ad82-6804d2acf2b7"",""Rating"":-1},
""1"":{""UID"":""eb41478e-e9bc-428e-8203-482f6a329666"",""Rating"":-13},
""2"":{""UID"":""a0922817-e706-4478-8995-d258bada488d"",""Rating"":6.0033992049},
""3"":{""UID"":""e0716752-56f4-49af-a811-ae55c69baa3d"",""Rating"":-4.9836395671},
""4"":{""UID"":""ec6bf376-17b5-4a9e-92be-990557551cd0"",""Rating"":-7.754526396}
}";
var result = JsonConvert.DeserializeObject<Dictionary<int,MyCustomClass>>(json);
MyCustomClass
public class MyCustomClass
{
public Guid UID {get;set;}
public decimal Rating {get;set;}
}
In the Dictionary<int, MyCustomClass> the int is the numeric key in your Json.
Note: I am using Newtonsoft Json here.
Once you have done the above you can sort it like the following using LINQ:
var sorted = result.OrderBy(x => x.Value.Rating);
// OR
var sorted = result.OrderByDescending(x => x.Value.Rating);

Categorizing string based on input in C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Title is like tl;dr version, here is what I mean:
I made currently just a string (to be a file with text), and I am splitting this string into separate words. I would like to make a method that allows me to mark words based on string/file. For example:
string nameOfString = "John likes pancakes";
Categorize(string nameOfString, class nameOfCategory)
this method would make John, likes and pancakes into a category (like Stupid, bestTexts) I passed to nameOfCategory.
I would like to count then the words into all of the categorys, so probably should use some kind of array top do this. Can someone help me with this? The big problem is I really have no idea how to pass the category (as a seperate class or just a string, maybe string[]?) and still be able to count it.
static void Main(string[] args)
{
var inputList = new List<string>
{
"John likes pancakes",
"John hates watching TV",
"I like my TV",
};
var dic = new Dictionary<string, int>();
inputList.ForEach(str => AddToDictionary(dic, str));
foreach (var entry in dic)
Console.WriteLine(entry.Key + ": " + entry.Value);
}
static void AddToDictionary(Dictionary<string, int> dictionary, string input)
{
input.Split(' ').ToList().ForEach(n =>
{
if (dictionary.ContainsKey(n))
dictionary[n]++;
else
dictionary.Add(n, 1);
});
}

C# Multi Spintax - Spin Text [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I got this class that I'm using for spin text.
public class Spinner
{
private static Random rnd = new Random();
public static string Spin(string str)
{
string regex = #"\{(.*?)\}";
return Regex.Replace(str, regex, new MatchEvaluator(WordScrambler));
}
public static string WordScrambler(Match match)
{
string[] items = match.Value.Substring(1, match.Value.Length - 2).Split('|');
return items[rnd.Next(items.Length)];
}
}
But I need it to be able to spin multi spintax text.
As example
{1|2} - {3|4}
Returns: 2 - 4
So it works.
But:
{{1|2}|{3|4}} - {{5|6}|{7|8}}
Returns: 2|4} - {5|7}
So it doesn't work if there is spintax inside spintax.
Any help? :)
Regular expressions are not good in dealing with nested structures, which means you should probably try a different approach.
In your example, {{1|2}|{3|4}} - {{5|6}|{7|8}} is the same as {1|2|3|4} - {5|6|7|8}, so maybe you don't need nested spintax.

Categories

Resources