I am working in Asp.Net C#, on converting typed letters into textbox, to automatically be changed in cyrillic. If i type "B" should be displayed "Б"... I've made it on textchanged with autoPostBack:
string str = char.ConvertFromUtf32(66);
str = "Б";
txtBox.Text = str;
But is it possible for live converting immediately after entering the letter.
Related
I have searched up how to do this. All I got was removing text based on a index point. I would like to have it setup where it uses a string to remove text, instead of choosing the point.
Something along the lines of
string text1 = "Hello World!";
string text2 = "Hello";
string text3;
void RemoveText()
{
text3 = text1.Remove(text2);
Console.WriteLine(text3);
}
Output:
Console: World!
Is there a method that can remove text by using a string? I was looking at the Microsoft Docs, but the problem is that the string wouldn't have a denfinite spot that need to be removed.
text3 = text1.Replace(text2,string.empty);
If you wanted to get part of a user inputed responce, you would doing something along the lines of
string textToRemove = "set background ";
Console.WriteLine("Type 'set background ' then your color.");
string userInput = Console.ReadLine();
string answer = userInput.Replace(textToRemove, string.empty);
SetBackgroundColor(answer);
First what you want to do is set the text you don't care about/need
string textToRemove = "set background ";
Next you are going to tell the user what to input and get the input
Console.WriteLine("Type 'set background ' then your color.");
string userInput = Console.ReadLine();
We would then have to make a new string without the unnessary text
string answer = userInput.Replace(textToRemove, string.empty);
In this case we are using the input to set the background color. So we would write a function for changing the background color with a string argument for the color the user gave.
SetBackgroundColor(answer);
You could also use an If statment or an for/foreach statment to see if the user's text without the unneccasry text is in an array or list containing strings that are allowed to be used.
I've saved icon font character codes in database:
f130, f150, ...
How can I show this codes as Icon?
Button.Text = "\u" + IconEntity.Value; // Error: invalid escape character!
if i use string formating, the button's text did not show icon correctly!
Button.Text = #"\u" + IconEntity.Value; //Button Text = \uf130
When you write strings with an escape charecter, c# treats the following text as a single char. For example, writing the string "\u0041" Will result in the string printing as the single char A.
When you start writing "\u" and then break the string, it'll treat it as a sequence of charecters, rather than a single one.
What you can do, however is create a char variable from it's hex value. You can do it by simply casting an int variable or literal to char.
Try implementing something similar to this:
static void Main(string[] args)
{
var str = "41";
var i = int.Parse(str, NumberStyles.HexNumber);
// Prints the char "A"
Console.WriteLine((char) i);
}
I Have a textfile that has a value of multiple row text that don't have delimiter.
Here is the sample text on my textfile.
000100000080020201000000005309970000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003F
00010001008002020100010000530997000014820000148200010000012C00001482000014820000148200010000012C000014820000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101000000000000000000000000000000000000003F
then i must devide each every line in this format.
"XXXXXXXX-XXXX-XXXXXXXXXXXXXX-XX-XXXX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX-XXXXXX-XX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX".Split('-');
the out put is like this.
00010000-0080-02020100000000-53-0997-00000000-00000000-0000-00000000-00000000-00000000-00000000-0000-00000000-00000000-00000000-00000000-0000-00000000-00000000-00000001-00000000-0000-00000000-00000000-00000000-00000000-0000-00000000-00000000-000000-00-00000000-00000000-0000-00000000-0000003F
00010001-0080-02020100010000-53-0997-00001482-00001482-0001-0000012C-00001482-00001482-00001482-0001-0000012C-00001482-00000000-00000000-0000-00000000-00000000-00000000-00000000-0000-00000000-00000000-00000000-00000000-0000-00000000-00000000-010100-00-00000000-00000000-0000-00000000-0000003F
i imported it into a multiline textbox.
here is my code
private void btn_input_Click(object sender, EventArgs e)
{
string content;
content = File.ReadAllText(txt_path.Text);
string[] patern = "XXXXXXXX-XXXX-XXXXXXXXXXXXXX-XX-XXXX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX-XXXXXX-XX-XXXXXXXX-XXXXXXXX-XXXX-XXXXXXXX-XXXXXXXX".Split('-');
string mystring = content;
string regex = string.Empty;
string match = string.Empty;
for (int i = 0; i < patern.Length; i++)
{
regex += #"(\w{" + patern[i].Length + "})";
match += "$" + (i + 1).ToString() + "-";
}
match = match.Substring(0, match.Length - 1);
txt_textfile.Text = Regex.Replace(mystring, regex, match);
}
then i want to save to my database the text that i split in ('-'). but i dont know how to do it. I want to ask is there is something i can do for me to able to save it. Even in while importing it. or after importing it. anyway. Please Help. Thank you
Your Question is not that much clear.
all you have done there is format your input string.
I'm not sure about the way that you want to insert the values to database.
just guessing that you want to split the formatted text by '-' and insert that split values
one by one
in that case what you have to do is split the text in txt_textfile text box and get string array.
loop the array and insert values the database.
if this is not the answer that you looked for please comment here the exact thing that you want to do
Thanks :)
I can use the Alt Key with the Number Pad to type symbols, but how do I programmatically insert a Symbol (Pound, Euro, Copyright) into a Textbox?
I have a configuration screen so I need to dynamically create the \uXXXX's.
In C#, the Unicode character literal \uXXXX where the X's are hex characters will let you specify Unicode characters. For example:
\u00A3 is the Pound sign, £.
\u20AC is the Euro sign, €.
\u00A9 is the copyright symbol, ©.
You can use these Unicode character literals just like any other character in a string.
For example, "15 \u00A3 per item" would be the string "15 £ per item".
You can put such a string in a textbox just like you would with any other string.
Note: You can also just copy (Ctrl+C) a symbol off of a website, like Wikipedia (Pound sign), and then paste (Ctrl+V) it directly into a string literal in your C# source code file. C# source code files use Unicode natively. This approach completely relieves you from ever even having to know the four hex digits for the symbol you want.
To parallel the example above, you could make the same string literal as simply "15 £ per item".
Edit: If you want to dynamically create the Unicode character from its hex string, you can use this:
public static char HexToChar(string hex)
{
return (char)ushort.Parse(hex, System.Globalization.NumberStyles.HexNumber);
}
For example, HexToChar("20AC") will get you the Euro sign.
If you want to do the opposite operation dynamically:
public static string CharToHex(char c)
{
return ((ushort)c).ToString("X4");
}
For example CharToHex('€') will get you "20AC".
The choice of ushort corresponds to the range of possible char values, shown here.
I cant believe this was difficult to find on the internet!
For future developers,if you have the unicode character its easy to do. eg:
C#:
var selectionIndex = txt.SelectionStart;
string copyrightUnicode = "00A9";
int value = int.Parse(copyrightUnicode, System.Globalization.NumberStyles.HexNumber);
string symbol = char.ConvertFromUtf32(value).ToString();
txt.Text = txt.Text.Insert(selectionIndex, symbol);
txt.SelectionStart = selectionIndex + symbol.Length;
VB.Net
Dim selectionIndex = txt.SelectionStart
Dim copyrightUnicode As String = "00A9"
Dim value As Integer = Integer.Parse(copyrightUnicode, System.Globalization.NumberStyles.HexNumber)
Dim symbol As String = Char.ConvertFromUtf32(value).ToString()
txt.Text = txt.Text.Insert(selectionIndex, symbol)
txt.SelectionStart = selectionIndex + symbol.Length
hi I have some text boxes which user enters information such as first name,last name ,... .
I need to convert text boxes' text to hex and then convert the hex to bytes and send to device via rs232.
I know the sending via rs232 part and I also know how to convert text to bytes.
My problem is ,now, I should work with Persian characters in text boxes .It means the text for name in text box would for example like this "حسین".
How can I solve my problem?
If i understand correctly you can try something like that
byte[] yourStrBytes = Encoding.GetEncoding("your encoding").GetBytes("your str");
string hexStr = BitConverter.ToString(yourStrBytes).Replace("-", "");
byte[] hexStrBytes=Encoding.UTF8.GetBytes(hexStr);
As I know if you want to convert a Persian or Arabic text to it's continuse unicode in order to send them to other devices via a serial port like This question you can use following code to reach HEX values of a Persian or Arabic letter.
private string ConvertToUTF(string input_text)
{
string _out = String.Empty;
char[] _chars = input_text.ToCharArray();
foreach (char c in _chars)
{
_out += ((Int16)c).ToString("X4");
}
return _out;
}
Useage:
Console.WriteLine(ConvertToUTF("سلام"));
Console.WriteLine(ConvertToUTF("مرحبا"));
Provide this out put
0633064406270645
06450631062D06280627