Visual C#

Page

 


 


 

nums_Vertical_4 = new List<int> { 2, 5, 3, 0, 4, 6, 8, 7, 1, 9 };
richTextBox4.AppendText(“” + nums_Vertical_4[0] + nums_Vertical_4[1] + nums_Vertical_4[2] + nums_Vertical_4[3] + nums_Vertical_4[4] + nums_Vertical_4[5] + nums_Vertical_4[6] + nums_Vertical_4[7] + nums_Vertical_4[8] + nums_Vertical_4[9]);


Build string from Numeric Value


newString1 = String.Format(“{0:D3}”, (int)numericUpDown4.Value);//temp1
newString2 = String.Format(“{0:D3}”, (int)numericUpDown5.Value);//temp2
// sprintf
StringBuilder sb = new StringBuilder();
sb.Append(“:dispaly_sett;”);
sb.Insert(13, newString1);
sb.Insert(16, newString2);

string RxString = sb.ToString(); //


Get Color from tabe


colorDialog1.ShowDialog();
// Get ARGB of colorDialog.
int argb = colorDialog1.Color.ToArgb();
// Get the color black by using the argb integer.
Color color = Color.FromArgb(argb);
/*
richTextBox2.AppendText(“Argb = ” + argb + “\r\n”);
richTextBox2.AppendText(”  R = ” + color.R);
richTextBox2.AppendText(”  G = ” + color.G);
richTextBox2.AppendText(”  B = ” + color.B);
richTextBox2.AppendText(“\r\n END  \r\n”);
*/
numericUpDown19.Value = (color.R);
numericUpDown20.Value = (color.G);
numericUpDown21.Value = (color.B);
button16.BackColor = Color.FromArgb(argb);


 Save text to file (tw- text writer)


 

// create a writer and open the file
TextWriter tw = new StreamWriter(“t_sett.tntm”);//, Encoding.UTF8, Encoding.Unicode

// write a line of text to the file
tw.WriteLine(MyStringBuilder);//DateTime.Now

// close the stream
tw.Close();


 change_simbol


public int  change_simbol (string incoming)
{
//***********       *****************************
string str = incoming;
char[] chars = str.ToCharArray();
int animalIndex = str.IndexOf(“+”);
if (animalIndex != -1)
{
chars[animalIndex++] = ‘=’;
}

string str2 = new string(chars);
//incoming = str2;
RxString1 = str2;
return animalIndex;
}

 


Remuve_first_INT_char_from_string


//********************************************************************************
//*****************   Remuve_first_INT(*)_char_from_string  *************************
//********************************************************************************
string Remuve_first_INT_char_from_string(string abc, int location_in_abc)
{
string abc1 = abc.Insert(location_in_abc + 1, “!”);
string abc2 = abc1.Replace(“*!”, “^”);
return abc2;
}


 

Clear string from incorrect characters


static string CleanInput2(string strIn)
{
// Replace invalid characters with empty strings.
return Regex.Replace(strIn, @”[^\w\.@-]”, “-“);
}


  Reverse string


private void button16_Click_1(object sender, EventArgs e)
{

RxString1 = richTextBox3.Text;
richTextBox3.Clear();
char[] outputBinChars = RxString1.ToCharArray();

//Reverse
Array.Reverse(outputBinChars);

//build a string from the processed characters and return it
richTextBox3.AppendText(new string(outputBinChars));
/*
//******************   ReachTextBox3  ******************************
Int_temp = FindMyText(“11010”, 0, 50);
if (Int_temp != -1)//
{
richTextBox2.AppendText(“\r\n String 11010 Finded @ position ” + Int_temp + ” in Styring : “);
}
else richTextBox2.AppendText(“\r\n String NOT Finded “);
*/
//******************   ReachTextBox3  ******************************
HighlightPhrase(richTextBox3, “12345”, Color.Lime);
HighlightPhrase(richTextBox3, “54321”, Color.Lime);
}

 


HighlightPhrase


private void HighlightPhrase(RichTextBox x, string phrase, Color color)
{
int pos = richTextBox3.SelectionStart;
string s = x.Text;
for (int ix = 0; ; )
{
int jx = s.IndexOf(phrase, ix, StringComparison.CurrentCultureIgnoreCase);
if (jx < 0) break;
x.SelectionStart = jx;//
x.SelectionLength = phrase.Length;//
x.SelectionColor = color;         //
ix = jx + 1;
}
x.SelectionStart = pos;
x.SelectionLength = 0;
}


Find string in Rich Text Box


//If the search string is found in the RichTextBox,
//the method returns the index location of the first character
//of the found text and highlights the found text; otherwise, it returns a value of -1.
//http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.find(v=vs.71).aspx

public int FindMyText(string searchText, int searchStart, int searchEnd)
{
// Initialize the return value to false by default.
int returnValue = -1;

// Ensure that a search string and a valid starting point are specified.
if (searchText.Length > 0 && searchStart >= 0)
{
// Ensure that a valid ending value is provided.
if (searchEnd > searchStart || searchEnd == -1)
{
// Obtain the location of the search string in richTextBox1.
int indexToText = richTextBox3.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase);
// Determine whether the text was found in richTextBox1.
if (indexToText >= 0)
{
// Return the index to the specified search text.
returnValue = indexToText;
}
}
}

return returnValue;
}

 


      //Swaps the cases in a string
//word -> WORD
//Word -> wORD
//WoRd -> wOrD


public static string SwapCases(string input)
{
StringBuilder ret = new StringBuilder();
for (int i = 0; i < input.Length; i++)
{
if (string.Compare(input.Substring(i, 1), input.Substring(i, 1).ToUpper(), false) == 0)
ret.Append(input.Substring(i, 1).ToLower());
else
ret.Append(input.Substring(i, 1).ToUpper());
}
return ret.ToString();
}


 hex2binary


private string hex2binary(string hexvalue)
{

string binaryval = “”;

binaryval = String.Format(“{0:00000000}”, double.Parse(Convert.ToString(Convert.ToByte(hexvalue, 16), 2)));
// Returns a string with characters in reverse order.
//Validate input
if (string.IsNullOrEmpty(binaryval))
return string.Empty;

char[] outputChars = binaryval.ToCharArray();

//Reverse
Array.Reverse(outputChars);

//build a string from the processed characters and return it
return new string(outputChars);
//return binaryval;

}

 


Only Hex In String


bool OnlyHexInString(string text)
{
for (var i = 0; i < text.Length; i++)
{
var current = text[i];
if (!(Char.IsDigit(current) || (current >= ‘a’ && current <= ‘f’)))
{
return false;
}
}
return true;
}


 Goto


private void Goto(RichTextBox myRichTextBox, Int32 lineToGo)
{
Int32 j = 0;
String text = myRichTextBox.Text;
if (lineToGo > myRichTextBox.Lines.Length)
lineToGo = myRichTextBox.Lines.Length;
for (Int32 i = 1; i < lineToGo; i++)
{
j = text.IndexOf(‘\n’, j + 1);
if (j == -1) break;
}
if (lineToGo > 1)
{
myRichTextBox.Select(j + 1, 0);
}
else
{
myRichTextBox.Select(j, 0);
}
}
 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Confirm that you are not a bot - select a man with raised hand: