Error
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.

string

Execute script file of sql server from vb.net code
Saturday, 28 January 2012 01:48
// Execute script file of sql server from vb.net code



Public Shared Function ExceuteScriptFile(ByVal ScriptFilePath As String, Optional ByVal MyConnectionKey As String ) As Integer
Dim db As Database
Dim MyServer As String = AppSettings("Server")
Dim MyUserName As String = AppSettings("userid")
Dim MyPassword As String = AppSettings("password")
Dim MyDbName As String = AppSettings("DBName")

Dim ScriptExeceute As New Process
Dim osqlParams As String = ""
db = DatabaseFactory.CreateDatabase(MyConnectionKey )
ScriptFilePath = """" + ScriptFilePath + """"
osqlParams = String.Format("-S {0} -U {1} -P {2} -d {3} -i ", MyServer, MyUserName, MyPassword, MyDbName)
ScriptExeceute.StartInfo.FileName = "sqlcmd.exe"

Try
ScriptExeceute.StartInfo.Arguments = osqlParams & ScriptFilePath
ScriptExeceute.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
ScriptExeceute.Start()
ScriptExeceute.WaitForExit()
Catch ex As Exception

End Try
Return 0
End Function

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/tcVwUBCikIk/14505

 
Join multiple strings with single string
Friday, 23 December 2011 00:10
There are two ways to join multiple strings: using the + operator that the String class overloads, and using the StringBuilder class. The + operator is easy to use and makes for intuitive code, but it works in series; a new string is created for each use of the operator, so chaining multiple operators together is inefficient.

Example: 1

string two = "two";
string str = "one " + two + " three";
System.Console.WriteLine(str);


Example: 2

string two = "two";

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("one ");
sb.Append(two);
sb.Append(" three");
System.Console.WriteLine(sb.ToString());

string str = sb.ToString();
System.Console.WriteLine(str);

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/l-AqaNAKW5I/14305

 
How can split strings on different characters with single-character or string delimiters?
Friday, 23 December 2011 00:08
Use Split to separate parts from a string. If your input string is "A,B,C" you can split on the comma to get an array of: "A" "B" "C".

class Program
{
static void Main()
{
string s = "there is a cat";
//
// Split string on spaces.
// ... This will separate all the words.
//
string[] words = s.Split(' ');
foreach (string word in words)
{
Console.WriteLine(word);
}
}
}

//OUTPUT

there
is
a
cat

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/SYJ20_L4CKY/14303

 
Cool use of String.Format method
Wednesday, 14 December 2011 02:05
The string.Format method is a static method that receives a string that specifies where the following arguments should be inserted, and these are called substitutions

Following example shows the use of the string.Format method to combine three strings with formatting options. The format string itself is the first argument to the string.Format method and it is specified as a string literal.

The position markers in the format string are specified to the left of the colons, and this means the "0", "1:", and "2:" indicate where the first, second, and third arguments are inserted. The part after the ":" and in between the { } brackets indicates the exact format specification for that variable.

String Literal

static void Main()
{
//
// Declare three variables that we will use in the format method.
// ... The values they have are not important.
//
string value1 = "This is test";
int value2 = 530;
DateTime value3 = new DateTime(2011, 11, 11);
//
// Use string.Format method with four arguments.
// ... The first argument is the formatting string.
// ... It specifies how the next three arguments are formatted.
//
string result = string.Format("{0}: {1:0.0} - {2:yyyy}",value1,value2,value3);
Console.WriteLine(result);
}
/*
OUTPUT
This is test: 530.0 - 2011
*/


Number formats
You can specify that a value type such as a double can be formatted inside the string.Format method based on the format string. The format string is the first argument to the string.Format method. The format string in this example uses the 0:0.0% syntax, which means that the second argument should be formatted with the pattern 0.0%. The arguments are numbered starting at zero.

static void Main()
{
//
// Format a ratio as a percentage string.
// ... You must specify the percentage symbol in the format string.
// ... It will multiply the value by 100 for you.
//
double ratio = 0.530;
string result = string.Format("string = {0:0.0%}",ratio);
Console.WriteLine(result);
}
/*
OUTPUT
string = 530.0%
*/


Padding (PadLeft and PadRight)
Padding can be used with strings in the C# language and this can be expressed declaratively in formatting strings and the string.Format method. The term 'padding' indicates that you are inserting a variable number of characters at the left or right of the string to ensure that the total length of the string is a fixed length. Instead of the PadLeft and PadRight methods, you can use the string.Format method with special substitutions.

static void Main()
{
//
// The constant formatting string.
// ... It specifies the padding.
// ... A negative number means to left-align.
// ... A positive number means to right-align.
//
const string format = "{0,-10} {1,10}";
//
// Construct the strings.
//
string line1 = string.Format(format,100,5);
string line2 = string.Format(format,"Carrot","Giraffe");
Console.WriteLine(line1);
Console.WriteLine(line2);
}
/*
OUTPUT
100 5
Carrot Giraffe
*/


ToString or string.Format
Sometimes, you need to just format a single number, like an integer or long. In this case, you don't need to use string.Format. You can just use the ToString virtual method.

static void Main()
{
int value = 123;
string a = string.Format("{0:0000}", value); // Too complex
string b = value.ToString("0000"); // Simpler
Console.WriteLine(a);
Console.WriteLine(b);
}
/*
OUTPUT
0123
0123
*/


DateTime Format
format string pattern defined as followse
MMM display three-letter month
ddd display three-letter day of the WEEK
d display day of the MONTH
HH display two-digit hours on 24-hour scale
mm display two-digit minutes
yyyy display four-digit year


static void Main()
{
DateTime time = DateTime.Now; // Use current time
string format = "MMM ddd d HH:mm yyyy"; // Use this format
Console.WriteLine(time.ToString(format)); // Write to console
}
/*
OUTPUT
Feb Fri 27 11:41 2009
*/

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/DUa-Zy493Oo/14175

 
How to Split and Join Strings
Wednesday, 14 December 2011 01:31
A program may wish to process data from an Excel spreadsheet. Excel has the capability to export a worksheet in Comma Separated Value (CSV) format. Using the string Split() method allows you to extract the values from in between the commas. Similarly, the string Join() method will take individual values from an array and combine them with a separator, such as a comma. The listing below shows how to use the string Split() and Join() methods:


using System;
namespace CSharpSample
{
class StringJoinSplit
{
static void Main(string[] args)
{
// comma delimited string
string commaDelimited = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
Console.WriteLine("Original Comma Delimited String: \n{0}\n", commaDelimited);
/*
OUTPUT
Original Comma Delimited String:
Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
*/

// separate individual items between commas
string[] year = commaDelimited.Split(new char[] {','});
Console.WriteLine("Each individual item: ");
foreach(string month in year)
{
Console.Write("{0} ", month);
}
Console.WriteLine("\n");
/*
OUTPUT
Each individual item:
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
*/

// combine array elements with a new separator
string colonDelimeted = String.Join(":", year);
Console.WriteLine("New Colon Delimited String: \n{0}\n", colonDelimeted);
/*
OUTPUT
New Colon Delimited String:
Jan:Feb:Mar:Apr:May:Jun:Jul:Aug:Sep:Oct:Nov:Dec
*/

string[] quarter = commaDelimited.Split(new Char[] {','}, 3);
Console.WriteLine("The First Three Items: ");
foreach(string month in quarter)
{
Console.Write("{0} ", month);
}
Console.WriteLine("\n");
/*
OUTPUT
The First Three Items:
Jan Feb Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
*/

string thirdQuarter = String.Join("/", year, 6, 3);
Console.WriteLine("The Third Quarter: \n{0}\n", thirdQuarter);
/*
OUTPUT
The Third Quarter:
Jul/Aug/Sep
*/
}
}
}

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/zqo0wODQxpY/14173

 
Start
Prev
1


Page 1 of 3
Taxonomy by Zaragoza Online