get data from a .txt file and write it on a textbox - c#

I am trying to create a language translator I have the texts that translated the word that I need here is an example of what is inside my text file https://pastebin.com/LBv76w2f
and I have two text boxes in my program, I want to get data from the text box
and write it in the second text box based on the text file that I have the words in it something like
if (englishtextbox.Text == "yttrium")
{
kurdishtxtbox.Text = "لقي: پزيشكي" + "\r\n" + "كوردي: هێماي كيميايي ييتريۆمە" + "\r\n" + "وردەكاري: هێماي كيميايي ييتريۆمە ";
}
but you know I don't like to type 100 000 else ifs. thanks for help ;)

Create a table with 2 fields in DB
Column_1 column_2
Then use query
Select column_2 from table where column_1 = englishtextbox.Text

Related

richTextBox - add text and table

i want to add formatted text and table to a richTextBox.
For this I use these codes:
Text:
richTextBox1.SelectionFont = new Font("Maiandra GD", 30, FontStyle.Bold);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectionIndent = 0;
richTextBox1.AppendText("text text text");
And the table:
StringBuilder tableRtf = new StringBuilder();
tableRtf.Append(#"{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}");
for (int j = 0; j <5; j++)
{
tableRtf.Append(#"\trowd");
tableRtf.Append(#"\cellx2500" + " ghhghgjghjghjhggjh");
tableRtf.Append(#"\intbl\cell");
tableRtf.Append(#"\cellx10000\intbl\cel");
tableRtf.Append(" " + "sdfsdfs" + #"\intbl\clmrg\cell\row");
}
tableRtf.Append(#"\pard");
tableRtf.Append(#"}");
richTextBox1.Rtf=tableRtf.ToString();
But the
richTextBox1.Rtf=tableRtf.ToString();
kills the previous contents.
How can I make compatible them?
It is not a duplicate because I want two thing:
1) add formatted text to richTextBox this way:
richTextBox1.SelectionFont = new Font("Maiandra GD", 30, FontStyle.Bold);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.AppendText("text text text");
It is well readable and I can modify easily.
2) And I want to add tables.
So the structure:
text text text text text
text text text text text
|TABLE|
text text text text text
text text text text text
text text text text text
|TABLE|
etc.
But I don't know how can I apply tables without losing previous contents?
What you need to do is to dissect the rtf codes into the headers and the bodies.
The table body starts with the loop and keeping the \par is surely a good idea.
But you must neither replace the old text nor simply append the body to the end.
Instead you need to insert it before the last curly! This is because that last curly marks the end of the whole rtf code and anything after it will be ignored!
This was simple.
For a full solution you also will want to combine the headers.
This is a lot more work and writing it all out would go beyond an SO answer.
But the basic principle is simple:
You need to understand the things your table header adds to the things already in the primal header.
The most common things are afont table and a color table.
So if you want to use one or more different fonts in the appended table you need to do this:
add them to the font table with a new font index, e.g. as \f1\fnil Consolas; after the previous semicolon.
use it by changing the loop to include the new font right after the first \intbl table-paragraph-formatting control word: \intbl\f2\fs24 ghhghgjghjghjhggjh.
repeat as needed if you want to use different fonts in the table.
add a cfNfont color selector, if you want to.
The same idea will also work for the color table. It doesn't have a explicit indexing, so order matters; all colors are appended, each with a semicolon at the end:
{\colortbl ;\red255\green0\blue0;\red25\green0\blue220;}
..adds a blue color to the red from the formatted text.
You see, this is work and takes some effort and preparations.
You can find the full rtf specs here.
Here is a screenshot of playing a little with the rtf..:
Note that the parts of table header was created by the control; you may want to use a dummy control for this or maybe you can figure out which parts you need and which are not necessary..
Update: Here is a 'appending rtf for dummies' version:
tableRtf.Append(#"{\fonttbl{\f0\fnil\fcharset0 Courier;}}");
for (int j = 0; j <5; j++)
{
tableRtf.Append(#"\trowd");
tableRtf.Append(#"\cellx2500" + " ghhghgjghjghjhggjh");
tableRtf.Append(#"\intbl\cell");
tableRtf.Append(#"\cellx10000\intbl\cel");
tableRtf.Append(" " + "sdfsdfs" + #"\intbl\clmrg\cell\row");
}
tableRtf.Append(#"\pard");
tableRtf.Append(#"}");
string rtf1 = richTextBox1.Rtf.Trim().TrimEnd('}');
string rtf2 = tableRtf.ToString();
richTextBox1.Rtf = rtf1 + rtf2;
Note that the font table inserted before the table body does work! But make sure not to add the rtf-start tag!!

How to save to database the value on a multiline textbox or how to save to database a non-delimited text on a textfile

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 :)

How to Generate Sub String values From Value inserted in multiple textboxes

i have 2 tables in my database.1st is material_details and 2nd is category
in material_details i have 6 columns (Make,Series,capacitance,tolerance,material outing)
in 2nd i have(category id,category_Name)
i want to take values from users in text boxes and from that values want to generate a sub string.how can i do this? code in c sharp
this will make u understand better.......
"i am working on a demo website.on my webpage i have 5 labels and 5 text boxes. 1.category 2.make 3.series 4.capacity and the last text box is Sub string.Now i want that when ever the user fill the 1 to 4 text boxes.a sub string should be generated by the values of these text boxes..for example..if user enter the category as "school" make as "samsung" series as "1234" the sub string that will be generates is like "SCH-SAM-123"..the first three words from all field.""
//these codes will help you retrieve the values of each Text box to strings
TextBox objTextBox1 = (TextBox)input1;
string theText1 = objTextBox.Text;
Similarly generate 4 strings for each text box.
theText1
theText2
theText3
theText4
//This will extract first three characters from a string
string sub1 = theText1.Substring(0, 3);
Similarly extract characters from all the strings created above.
If you want the characters to be in upper case use "string.ToUpper()" method
Once all the strings are extracted, concatenate all strings
string results = sub1 + "-" + sub2 + "-" + sub3 "-" + sub4;
//Check the result
Console.WriteLine(results);
I hope this guide will help you to get your intended results.
Thanks

adding space in texbox results when sending thru email

wassup guys im new to C# coding and i did a search but couldn't find exactly what im looking for. So i have a couple of text-boxes which holds string elements and integers
what i want to do is when these boxes are filled in i want to send a summary of the email to client/customer but the format is whats getting me.
(first, one) are strings equaling different text-boxes
my code is:
emailCompseTask.Body = first + one + Enviroment.NewLine +
second + two + Enviroment.NewLine
and so on problem is which i send thru email it shows something like this:
computer service25.00
instead of:
computer service 25.00
is there a way to add spacing to make this more presentable? or even a better way perhaps thanks in advance guys
try this :
emailCompseTask.Body = first + one + " "+ second + two ;
body takes as HTML input, check here for more spacing option.
I'm a bit confused, but you just want to add some spacing in the output? Just throw some spaces in there like you would another variable.
first + " " + one + Environment.NewLine
+ second + " " + two + Environment.NewLine;
You can use a table
string tableRow = #"<tr>
<td>{0}</td>
<td>{1}</td>
</tr>";
string htmlTable = #"<table>
{0}
</table>";
string rows = "";
// Can do this in a loop
rows += string.Format(tableRow, first, one);
rows += string.Format(tableRow, first, one);
emailComseTask.Body = string.Format(htmlTable, rows);

How insert multiline text into a RichTextBox?

I'm using a Xceed.Wpf.Toolkit.RichTextBox that displays text saved in RTF. I've got a contextual menu that add some multi lines text at the caret position using this code
var text = "Line1" + Environment.NewLine + "Line2"
richTextBox.CaretPosition.InsertTextInRun(text);
It displays as I expect
Line1
Line2
When I save and reload the text (saved in RTF), it displays as this:
Line1Line2
When I look in the RTF code, it is saved without the CR and LF...
Why my CR/LF vanished? What is the solution to insert multi line text at the caret position?
I found how to do:
var text = "Line1" + Environment.NewLine + "Line2"
richTextBox.Control.Selection.Text = text;
Set RichTextBox.AcceptsReturn to True
http://social.msdn.microsoft.com/Forums/vstudio/en-US/f044f15b-48a4-485c-91c0-07a0828acb98/acceptsreturn-in-a-wpf-richtextbox

Categories

Resources