728x90
반응형
【 WPF & C# (C Sharp) 】 - Split / 문자열 자르기
@ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <Window x:Class="test.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:test" mc:Ignorable="d" Title="MainWindow" Height="377.436" Width="503.496"> <Grid> <Button x:Name="btn_delimiterChars" Content="delimiterChars" HorizontalAlignment="Left" Height="23" Margin="10,12,0,0" VerticalAlignment="Top" Width="95" Click="delimiterChars"/> <TextBox x:Name="TextBox1" HorizontalAlignment="Left" Height="130" Margin="10,40,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="95"/> <Button x:Name="btn_separatingChars" Content="separatingChars" HorizontalAlignment="Left" Height="23" Margin="10,175,0,0" VerticalAlignment="Top" Width="95" Click="separatingChars"/> <TextBox x:Name="TextBox2" HorizontalAlignment="Left" Height="130" Margin="10,203,0,-14" TextWrapping="Wrap" VerticalAlignment="Top" Width="95"/> <TextBlock x:Name="TextBlock1" HorizontalAlignment="Left" Margin="110,40,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/> <TextBlock x:Name="TextBlock2" HorizontalAlignment="Left" Margin="110,203,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/> <Button x:Name="btn_separatingChars2" Content="StringSplitOptions.RemoveEmptyEntries" HorizontalAlignment="Left" Height="23" Margin="252,175,0,0" VerticalAlignment="Top" Width="233" Click="separatingChars2"/> <TextBox x:Name="TextBox3" HorizontalAlignment="Left" Height="130" Margin="334,203,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="95"/> </Grid> </Window> | cs |
@ MainWindow.xaml.cs
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace test { /// <summary> /// MainWindow.xaml에 대한 상호 작용 논리 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); TextBlock1.Text = @" text = one\ttwo three:four,five six seven delimiterChars = { ' ', ',', '.', ':', '\t' }"; TextBlock2.Text = @" text = one<<two......three<<four; separatingChars = { <<, ... }"; } private void delimiterChars(object sender, RoutedEventArgs e) { { // Split 할 문자가 char 인 경우 char[] delimiterChars = { ' ', ',', '.', ':', '\t' }; string text = "one\ttwo three:four,five six seven"; string[] words = text.Split(delimiterChars, StringSplitOptions.None); foreach (string s in words) { TextBox1.Text += s + "\n"; } } } private void separatingChars(object sender, RoutedEventArgs e) { { // Split 할 문자가 char 인 경우 string[] separatingChars = { "<<", "..." }; string text = "one<<two......three<<four"; string[] words = text.Split(separatingChars, StringSplitOptions.None); foreach (string s in words) { TextBox2.Text += s + "\n"; } } } private void separatingChars2(object sender, RoutedEventArgs e) { { // Split 할 문자가 char 인 경우 string[] separatingChars = { "<<", "..." }; string text = "one<<two......three<<four"; string[] words = text.Split(separatingChars, StringSplitOptions.RemoveEmptyEntries); foreach (string s in words) { TextBox3.Text += s + "\n"; } } } } } | cs |
@ 그래도... 이게 제일 나은거 같다.
string[] splitDatas = source.Split(new string[] { "<span>" }, StringSplitOptions.None);
내용참조 : http://blog.naver.com/uutak2000/221044317252 [출처] [C#] Web Parsing (웹 파싱)|작성자 Plurdis
http://insurang.tistory.com
728x90
반응형
'Programing (프로그래밍) > WPF & C# (C Sharp)' 카테고리의 다른 글
[ WPF & C# (C Sharp)] - 파일 만든 수정한 액세스 날짜 (2) | 2017.10.31 |
---|---|
[ WPF & C# (C Sharp)] - 다운로드 WebClient 방식 / Download (0) | 2017.10.30 |
WPF & C# - ini 파일 내 방식대로 읽기 ( ini / cfg / config / txt / sector / 섹터 ) (0) | 2017.10.30 |
[ WPF & C# (C Sharp)] - Lib.cs Lib.dll 만들기 (0) | 2017.10.27 |
[ WPF & C# (C Sharp)] - 두 txt 파일 한줄씩 읽어서 중복 값 제거 (0) | 2017.10.26 |
[ WPF & C# (C Sharp)] - ListView 예제 (2) | 2017.10.25 |
WPF & C# - 상대경로 구하기 / path ( MakeRelativeUri / Uri ) (0) | 2017.10.25 |
[ WPF & C# (C Sharp)] - 에러 메세지 발생 try ~ catch (0) | 2017.10.24 |