C# replace tab
string strWithTabs = “here is a string with a tab”; // tab-character char tab = ‘\u0009’; String line = strWithTabs.Replace(tab.ToString(), ” “);
string strWithTabs = “here is a string with a tab”; // tab-character char tab = ‘\u0009’; String line = strWithTabs.Replace(tab.ToString(), ” “);
XmlDocument doc = new XmlDocument(); doc.Load(“Book.xml”); XmlNodeList node = doc.GetElementsByTagName(“Books”); for (int i = 0; i < node.Count; i++) //방법1 { Console.WriteLine(node.Item(i).SelectSingleNode(“Name”).InnerText); } foreach (XmlNode […]
설치된 .NET Framework 버전 확인. %WINDIR%\Microsoft.NET\Framework 버전별 디렉토리 확인 닷넷 프레임워크 4.5 이상 이면 regedit 로 확인
1 2 3 |
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full |
4.6 버전인것을 확인 할 […]
//한글자가 숫자(1)인지 체크 public static int NumberCheck(string numString) { int retNumberCheck = 0; long number1 = 0; try{ bool canConvert = long.TryParse(numString, out number1); if […]
oledb connection string Provider=Microsoft.ACE.OLEDB.12.0; Data Source=|DataDirectory|local.accdb;User ID=Admin;Password=;Mode=ReadWrite;”;
Program that uses foreach with LINQ query [C#]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
using System; using System.Linq; class Program { static void Main() { // An unsorted string array. string[] letters = { "d", "c", "a", "b" }; // Use LINQ query syntax to sort the array alphabetically. var sorted = from letter in letters orderby letter select letter; // Loop with the foreach keyword. foreach(string value in sorted) { Console.WriteLine(value); } } } Output a b c d |
1. 선언
1 2 3 |
string str = "문자을 선업합니다"; |
2. 문자열 추가
1 2 3 4 5 6 7 8 9 10 11 |
string str ="만세"; str = str.Insert(0,"대한민국 "); str = str.Insert(str.Length," 입니다."); Console.WriteLine(str2); //test Console.ReadLine(); //test //결과 => 대한민국 만세 입니다. string str2 =String.Concat("대","한","민","국"); //결과 대한민국 |
3. 공백처리
1 2 3 4 5 6 |
string str = " 대한민국 "; str = str.TrimStart(); // 앞(왼쪽)쪽 문자열 삭제 str = str.TrimEnd(); // 뒤(오른쪽)쪽 문자열 삭제 str = str.Trim(); // 양쪽 문자열 삭제 |
4.문자열 찾아서 문자열 자르기 파싱(Parsing)
1 2 3 4 5 6 |
IndexOf( "검색할 문자열" ); LastIndexOf( "검색할 문자열" ); Substring( 자를 위치 첨자 ); Substring( 자를 위치 첨자, 첨자에서 자를 만큼의 길이 ); |
5. Split (분리) 시키기
1 2 3 4 |
string str = "가,나,다,라,마"; string [] result = str.Split(','); |
6. Replace(변환)
1 2 3 4 |
string str = "대한민국\r\n만세"; str = str.Replace( "\r\n", "<br>" ); |
7. 인덱스(Index)로 […]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Xml.Xsl; using System.Xml.XPath; using System.IO; namespace ConsoleXSLTest { class Program { static void Main(string[] args) { XmlDocument docXml = new XmlDocument(); XslCompiledTransform xslt = new XslCompiledTransform(); StringWriter stringWriter = new StringWriter(); string sDPW8 = Path.GetFileName(“DPW8.xml”); xslt.Load(Path.GetFileName(“DPW8.xsl”)); docXml = new XmlDocument(); docXml.PreserveWhitespace = false; docXml.LoadXml(sDPW8); xslt.Transform(docXml, null, stringWriter); docXml.LoadXml(stringWriter.ToString()); Console.WriteLine(docXml.OuterXml); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
//월화수목금토일 public static int WeekDay(DateTime dateTime) { int tempWeekDay = 0; var dt = dateTime.DayOfWeek; switch (dt) { case DayOfWeek.Monday: //월 tempWeekDay=1; break; case DayOfWeek.Tuesday: //화 tempWeekDay=2; break; case DayOfWeek.Wednesday: //수 tempWeekDay=3; break; case DayOfWeek.Thursday: //목 tempWeekDay=4; break; case DayOfWeek.Friday: //금 tempWeekDay=5; break; case DayOfWeek.Saturday: //토 tempWeekDay = 6; break; case DayOfWeek.Sunday: //일 tempWeekDay = 7; break; } return tempWeekDay; } |
Copyright © 2024 | WordPress Theme by MH Themes