i'm trying to fill one line of my label with hyphens. Here's what i got right now. what is the function that i can use to fill the next line without manually typing out all the hyphens?
lblResumé.Text = intNbrTotTut.ToString() + str1erePhrase + Environment.NewLine
string myString = "Test" + Environment.NewLine + "Test2" +Environment.NewLine;
label1.Text = myString.Replace(System.Environment.NewLine, "_");
Related
If I have a TreeView with the font to Segoa UI Emoji. I need to set a TreeView node icon using 2 strings but doesn't work. Also, what value can I use for the unicodeEndStr variable below if the unicode only has 4 digits like 2639 ?
// This code shows emoji icon in treeview node followed by a space and some text
string emoji = "\U0001F608" + " " + "Face Savoring Food";
EmojiTreeView.Nodes.Add(emoji);
// This code does not show emoji icon, just \U0001F608 followed by a space and some text
string unicodeStartStr = "\\U000"; // need double back slashes to compile
string unicodeEndStr = "1F608";
string emojiCodeStr = unicodeStartStr + unicodeEndStr;
string emojiStr = emojiCodeStr + " " + "Face Savoring Food";
EmojiTreeView.Nodes.Add(emojiStr);
First parse your combined Unicode string as hex(16-bit) number.
Then use char.ConverFromUtf32(str).ToString() to generate complete Unicode symbol.
Reference solution: Dynamic generate 8-Digit-Unicode to Character
public Form1()
{
InitializeComponent();
treeView1.Nodes.Add("\U0001F608" + " " + "Face Savoring Food");
// remove \u prefix
string unicodeStartStr = "000";
string unicodeEndStr = "1F608";
string emojiCodeStr = unicodeStartStr + unicodeEndStr;
int value = int.Parse(emojiCodeStr, System.Globalization.NumberStyles.HexNumber);
string result = char.ConvertFromUtf32(value).ToString();
string emojiStr = result + " " + "Face Savoring Food";
treeView1.Nodes.Add(emojiStr);
}
Worked result
How do I ident a set of lines when writing to a file, with a tabs? I need to go through each line in the variable and create 8 spaces or two tabs for each line, when writing to the new file.
If the string was one line, it would be easy, with " " + test, however this has multiple lines.
public static string testLine=
"Line1" + Environment.NewLine +
"Line2" + Environment.NewLine +
"Line3" + Environment.NewLine +
"Line4" + Environment.NewLine +
using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath, true))
{
file.WriteLine(testLine);
String is composed of new line, line breaks enters, etc .
Is there any Microsoft Ident function library to support this?
Needs to handle multiple string variables in the future.
All you need to do is prefix the string with whitespace or a tab and replace all occurences off newlines with a newline and a suitable whitespace:
testLine = " " + testLine.Replace( Environment.NewLine, Environment.NewLine + " " );
You can explicitly handle an empty string to avoid indenting nothing:
testLine = String.IsNullOrEmpty(testLine) ? testLine : " " + testLine.Replace( Environment.NewLine, Environment.NewLine + " " );
Substitute "\t" for " " to insert a tab character.
I have created an application. This app contains the five textboxes id, name, surname, age and score.
When a user clicks the "okay button", these values are stores in an sql database.
Additionally, I want to store all of these information in an QR code. And when I decode it, the information should be shown in the textboxes respectively.
These are the references I am using so far.
using AForge.Video.DirectShow;
using Zen.Barcode;
using ZXing.QrCode;
using ZXing;
I can encode an ID number into a picture box, like so:
CodeQrBarcodeDraw qrcode = BarcodeDrawFactory.CodeQr;
pictureBox1.Image = qrcode.Draw(textBox1.Text, 50);
But I want all of the values in the textboxes to be storee in this QR code.
How can i do that?
The essence of the solution is, that you have to combine all the values from the textboxes into one string. To seperate them after decoding the QR code, you have to add a special character between the data values, that does not exist insinde the user input. After decoding the QR code, you can seperate the values by splitting the string at each occurance of the special character.
This is the quick and dirty way of doing that. If you want the QR code to be conformant to any specific format (like vcard), you have to reserach what it takes to compose the data for this format.
I expect your users cannot enter more than one line into the textboxes, so the newline character can be used as seperator character.
Encode all the information into one QR code.
var qrText = textBox1.Text + "\n" +
textBox2.Text + "\n" +
textBox3.Text + "\n" +
textBox4.Text + "\n" +
textBox5.Text;
pictureBox1.Image = qrcode.Draw(qrText, 50);
You can decode the QR code and assigning the data to the different textboxes again.
var bitmap = new Bitmap(pictureBox1.Image);
var lumianceSsource = new BitmapLuminanceSource(bitmap);
var binBitmap = new BinaryBitmap(new HybridBinarizer(source));
var reader = new MultiFormatReader();
Result result = null;
try
{
result = reader.Decode(binBitmap);
}
catch (Exception err)
{
// Handle the exceptions, in a way that fits to your application.
}
var resultDataArray = result.Text.Split(new char[] {'\n'});
// Only if there were 5 linebreaks to split the result string, it was a valid QR code.
if (resultDataArray.length == 5)
{
textBox1.Text = resultDataArray[0];
textBox2.Text = resultDataArray[1];
textBox3.Text = resultDataArray[2];
textBox4.Text = resultDataArray[3];
textBox5.Text = resultDataArray[4];
}
You can get this done by implementing below code :
"{" + '"' + "name" + '"' + ":" + '"' + txtName.Text + '"' + "," + '"' + "lname" + '"' + ":" + '"' + txtLname.Text + '"' + "," + '"' + "Roll" + '"' + ":" + '"' + txtRoll.Text + '"' + '"' + "class" + '"' + ":" + '"' + txtClass.Text + '"' + "}"
Result will be:
{"name":"Diljit","lname":"Dosanjh","Roll","2071","class":"BCA"}
Such that your QR scanner will recognize the data belong to its specific filed.
I need to insert in a specific position of the string line, another string, so I compute the specific position for start to insert:
string info1 = "info1";
string info2 = "info2";
string info3 = "info3";
string info4 = "info4";
string keyWord = "BELEGIT";
start = line.IndexOf(keyWord, 0) + keyWord.Length + 13;
var aStringBuilder = new StringBuilder(line);
aStringBuilder.Remove(start, 19);
line = aStringBuilder.ToString();
string newLine = line.Insert(start, "\r\n" + info1 + "\r\n" + "\r\n" + info2 + "\r\n" + info3 + "\r\n" + info4 + "\r\n");
(newLine will be the content of a file in my application).
newline contains the correct content except the string "00000" that inserts after "info4". So in my new file with the content that is newline there is newline and immediately after "00000". I do not really understand why.
Thanks in advance.
INPUT:
line contains:
#~11\r\nT-02040121R\r\n\r\n\r\n\r\n\r\n\r\n\n2.000000000\r\n
OUTPUT
newLine contains:
#~11\r\nT-02040121R\r\ninfo1\r\n\r\ninfo2\r\ninfo3\r\ninfo4\r\n00000\r\n
Assuming that you want just the first 19 chars of lineyou could use Substringto get them and string.Formatto build the new string.
Something like this
var start = line.Substring(0, 19);
string newLine = $"{start}\r\n{info1}\r\n\r\n{info2}\r\n{info3}\r\n{info4}\r\n";
The second line is the short form for
string newLine = string.Format("{0}\r\n{1}\r\n\r\n{2}\r\n{3}\r\n{4}\r\n", start, info1, info2, info3, info4);
if you need more information about string.Formathave a look at the MSDN.
I have written two lines of code below in vb6. The code is :
d = InStr(s, data1, Chr(13), 1) ' Fine 13 keycode(Enter) form a text data.
sSplit2 = Split(g, Chr(32)) ' Split with 13 Keycode(Enter)
But I can't write above code in C#. Please help me out. How can I write the above code in C#.
I believe you are looking for string.Split:
string str = "Test string" + (char)13 + "some other string";
string[] splitted = str.Split((char)13);
Or you can use:
string[] splitted = str.Split('\r');
For the above you will get two strings in your splitted array.
the equivalnt code for sSplit2 = Split(g, Chr(32)) is
string[] sSplit2 = g.Split('\n');
int index = sourceStr.IndexOf((char)13);
String[] splittArr = sourceStr.Split((char)13);
const char CarriageReturn = (char)13;
string testString = "This is a test " + CarriageReturn + " string.";
//find first occurence of CarriageReturn
int index = testString.IndexOf(CarriageReturn);
//split according to CarriageReturn
string[] split = testString.Split(CarriageReturn);
If you want to encapsulate the carriage return depending on whether you are running in a unix or non unix environment you can use Environment.NewLine . See http://msdn.microsoft.com/en-us/library/system.environment.newline(v=vs.100).aspx .
string testString2 = "This is a test " + Environment.NewLine + " string.";
//find first occurence of Environment.NewLine
int index2 = testString2.IndexOf(Environment.NewLine);
//split according to Environment.NewLine
string[] split2 = testString2.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);