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
Related
Just a C# beginner here that just build his first application and now wants to make some changes to make it more ideal.
Today I got three textboxes where the users type in year, month and project number.
When they click GO the application opens the respective folder: L:\2019\01\20190133
I would like to make it simpler, one textbox that gets divided into three strings (year, month, PO-number).
Any ideas? Sorry for the bad format of this post, feel free to correct/shame me :)
Current code:
private void button1_Click(object sender, System.EventArgs e)
{
int tbyear;
int tbmonth;
int tbpnr;
tbyear = int.Parse(textBox1.Text);
tbmonth = int.Parse(textBox2.Text);
tbpnr = int.Parse(textBox3.Text);
string tby = textBox1.Text;
string tbm = textBox2.Text;
string tbnr = textBox3.Text;
string path = Path.Combine(tby, tbm);
string pathnr = textBox1.Text + textBox2.Text + textBox3.Text;
System.Diagnostics.Process.Start("explorer.exe", #"L:\" + path + "\\" + pathnr);
As a very simple example of text extraction, use Substring.
string textFromInputControl = "20190133";
string year = textFromInputControl.Substring(0, 4); // start at index 0, 4 chars long
string month = textFromInputControl.Substring(4, 2); // start at index 4, 2 chars long
string poNumber = textFromInputControl.Substring(6); // start at index 6, all remaining chars
Console.WriteLine(year); // "2019"
Console.WriteLine(month); // "01"
Console.WriteLine(poNumber); // "33"
There are, of course, more complex ways of doing text extraction, like Regex. Use other tools when they are more appropriate.
I think that it's fine as it is. If you have 3 differents inputs in 3 differents textboxes it's well designed.
Imagine that one day you make a change and you don't want to join these types for generate your path: year\month\projectNumber.
This would implies to change UI + Code. If you keep your input in only 1 text box, the changes only affect to code.
I'm not so sure that entering all three items into one textbox is simpler from a user's perspective, but if you want to do that here's one way:
This assumes that the entries are separated in some way (we'll go with a space character).
var parts = textbox.Text.Split(' ');
var pathToOpen = $#"L:\{parts[0]}\{parts[1]}\{parts[2]}";
The above code splits the contents of the textbox by its ' ' delimiter, then formats them into a path in the format you provided.
Edit: going by the comments, you don't want to have a delimiter. In the case that your first two parts of the path are of fixed length, you can use the Substring method to extract them:
var year = textbox.Text.Substring(0, 4);
var month = textbox.Text.Substring(4, 2);
var rest = textbox.Text.Substring(6);
I'm Printing order in a receipt-like format to a RichtextBox, everything works just fine when my item name is in English, once my item name is a non-English language like Hebrew or Arabic where these two languages are written from right-to-left, the overall format becomes messy.
Example when all text is in English
1...5...10...15...20...25...30...35...40...45.48
ITM Price QTY Value
------------------------------------------------
Test 6,000 x1 6,000
test02 0 x1 0
test03 0 x1 0
As you Can see, everything is tidy and well-formatted, but when I have an Item which its name is in Hebrew or Arabic, This is what happens
1...5...10...15...20...25...30...35...40...45.48
ITM Price QTY Value
------------------------------------------------
Test 6,000 x1 6,000
1,500 تيست x1 1,500
As you can see, the Non-English text shifts under Price Column. As I mentioned, this happens only with languages written from Right-To-Left.
My code which does the formatting
int Item_Length = -29;
int Price_Length = -8;
int Qty_Length = -3;
int Value_Length = 8;
string Seperator = "------------------------------------------------"+"\n";
string ruler = "1...5...10...15...20...25...30...35...40...45.48"+"\n";
rTxtReceipt.Text = ruler;
string Headers = string.Format("{0,"+Item_Length+"}{1,"+Price_Length+"}{2,"+Qty_Length+"}{3,"+Value_Length+"}", "ITM", "Price", "QTY", "Value")+"\n";
rTxtReceipt.AppendText(Headers);
rTxtReceipt.AppendText(Seperator);
string Rows = null;
foreach (var item in Items_List)
{
Rows += string.Format("{0,"+Item_Length+"}{1," + Price_Length + ":N0}{2," + Qty_Length + "}{3," + Value_Length + ":N0}", item.ItemName, item.ItemSellPrice, ("x" + item.SellsQty), item.SellsValue) + "\n";
}
rTxtReceipt.AppendText(Rows);
Where rTxtReceipt is a RichTextBox Control.
Can anyone advise how to make all the texts regardless of the language to be aligned from left to right?
I do have a function where it can detects if text is in English or not, but I don't know where to change if the text was not in Egnlish.
public bool IsEnglish(string inputstring)
{
Regex regex = new Regex(#"[A-Za-z0-9 .,-=+(){}\[\]\\]");
MatchCollection matches = regex.Matches(inputstring);
if (matches.Count.Equals(inputstring.Length))
return true;
else
return false;
}
}
The problem has to do with how RTL characters behave when surrounded by numbers in bidirectional text. For more information, you may read this article:
Right-to-left language support and bidirectional text
You wouldn't have faced this problem if, say, instead of the price immediately following the item name, you had a Latin letter: تيست x1,500.
Well obviously, that's not what you want. So, to force the direction of text to remain LTR and prevent the numbers from messing it up, you simply add a "hidden character" immediately after the item name. Fortunately, there's a specific character that is used for this purpose. It's called a Left-to-Right Mark.
First, add the following constant somewhere appropriate:
const string LtrMark = "\u200E";
And then you can simply do something like this: *
Rows += string.Format(format, item.ItemName + LtrMark, item.ItemSellPrice, ...
// ^^^^^^^
Now, you don't have to worry about checking whether the item name is in English or not. Simply inserting that character will work for both LTR and RTL languages. Do note, however, that you need to use a fixed-width font that works for both English and Arabic (Courier New, for example). And this is how the final result would look like:
* Because the LTR mark is a zero-width character, it will make the following values appear one character behind. To avoid this, you may use Item_Length - 1 for the items or Item_Length + 1 for the headers to make sure they're aligned.
Let's say I wanted to create a simple calculator, and I have it set up so whenever you press one of the operation buttons (+,-,*,/), it sets whatever you have in the textbox as the first number and then add the operation to the textbox. Now if I wanted the second number to be set to whatever is after the operation (+,-,*, or /) when I press the solve button, how would I go about doing that?
You can use the string Split method to get your factors like this:
string calculation = "5+1";
string[] factors = calculation.Split('+');
//factors[0] == 5
//factors[1] == 1
To handle string splitting on multiple operands use:
string calculation = "4+8-2";
string[] factors = calculation.Split(new char[] {'+' , '-' });
//factors[0] == 4
//factors[1] == 8
//factors[2] == 2
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
I am trying to pick out specific letters/numbers from a text box, because each means something. After that I am trying to display in a label what it means.
So if I have a number AB-123456, I need to first pick out AB something like:
If (textBox.Text.Substring(0,2) == "AB") {
//Display to a label
}
First off, this doesn't work and I also tried substring(0,1) but also was receiving errors when I used my clear button to clear the text box.
After that I still need to pull the rest of the numbers. The next one I need to pull and define is 123, then 4 by itself, 5 by itself, and six by itself.
How do I go about pulling each of these individually if substring isnt working?
Try this:
if (textBox.Text.StartsWith("AB"))
{
//Display to a label
}
Use this if you don't want to have to check the Length of the text first. Also, you can include a StringComparison argument if you want to ignore case.
string input = textBox.Text;
// check the length before substring
If (input.Length >= 2 && input.Substring(0,2) == "AB") {
//Display to a label
}
or use regex:
string txt="AB-1234562323";
string re="AB-(\\d+)"; // Integer Number 1
Regex r = new Regex(re,RegexOptions.IgnoreCase|RegexOptions.Singleline);
Match m = r.Match(txt);
if (m.Success)// match found
{
// get the number
String number=m.Groups[1].ToString();
}