본문 바로가기

Programing (프로그래밍)/WPF & C# (C Sharp)

[ WPF & C# (C Sharp)] - Split / 문자열 자르기

728x90
반응형

【 WPF & C# (C Sharp) 】 - Split / 문자열 자르기



Split.zip




 @ 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


내용참조 : https://docs.microsoft.com/ko-kr/dotnet/csharp/programming-guide/strings/how-to-parse-strings-using-string-split




 @ 그래도... 이게 제일 나은거 같다.

string[] splitDatas = source.Split(new string[] { "<span>" }, StringSplitOptions.None); 


내용참조 : http://blog.naver.com/uutak2000/221044317252 [출처] [C#] Web Parsing (웹 파싱)|작성자 Plurdis






http://insurang.tistory.com


728x90
반응형