Trim









How do I use Trim
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: frmCapNhat.cs Copy
54         private void listView1_SelectedIndexChanged(object sender, EventArgs e)
55         {
56             bool bdapan = false;
57             for (int i = 0; i < listView1.Items.Count; i++)
58             {
59                 if (listView1.Items[i].Selected)
60                 {
61                     textBox5.Text = listView1.Items[i].SubItems[0].Text;
62                     textBox1.Text = listView1.Items[i].SubItems[2].Text;
63                     textBox2.Text = listView1.Items[i].SubItems[3].Text;
64                     textBox3.Text = listView1.Items[i].SubItems[4].Text;
65                     textBox4.Text = listView1.Items[i].SubItems[5].Text;
66                     richTextBox1.Text = listView1.Items[i].SubItems[1].Text;
67                     string t = listView1.Items[i].SubItems[6].Text.ToString().Trim();
68                     if (t.Length >= 2)
69                     {
70                         for (int ii = 0; ii < t.Length; ii++)
71                         {
72                             t2 = t[0].ToString();
73                             if (t[1].ToString() == "")
74                             {
75                                 t1 = "NULL";
76                             }
77                             else
78                             {
79                                 t1 = t[1].ToString();
80                             }
81                         }
82                     }
83                     else
84                     {
85                         t2 = t;
86                         t1 = "NULL";
87                     }
88                     Macdinh();
89                     if (t1 == "A")
90                     {
91                         checkBox1.Checked = true;
92                     }
93                     if (t1 == "B")
94                     {
95                         checkBox2.Checked = true;
96                     }
97                     if (t1 == "C")
98                     {
99                         checkBox3.Checked = true;
100                     }
101                     if (t1 == "D")
102                     {
103                         checkBox4.Checked = true;
104                     }
105
106                     if (t2 == "A")
107                     {
108                         checkBox1.Checked = true;
109                     }
110                     if (t2 == "B")
111                     {
112                         checkBox2.Checked = true;
113                     }
114                     if (t2 == "C")
115                     {
116                         checkBox3.Checked = true;
117                     }
118                     if (t2 == "D")
119                     {
120                         checkBox4.Checked = true;
121                     }
122                     bdapan = true;
123                 }
124                 if (bdapan == false)
125                 {
126                     Bandau();
127                 }
128             }
129
130         }
File name: frmCapNhat.cs Copy
140         private void LoadDataToListView()
141         {
142
143             sqlcmd = new SqlCommand("select cauhoi.mach,cauhoi,a,b,c,d,dapan from cauhoi,dapan where dapan.mach = cauhoi.mach and trinhdo = '" + g_sCapDo + "'", sqlcon);
144             SqlDataReader sqlreader = sqlcmd.ExecuteReader();
145             listView1.Items.Clear();
146             while (sqlreader.Read())
147             {
148                 ListViewItem lvitem = new ListViewItem();
149                 //lvitem.Text = sqlreader["MaCH"].ToString();
150                 //lvitem.SubItems.Add(sqlreader["cauhoi"].ToString());
151
152                 //string sMaCH = sqlreader["mach"].ToString();
153
154                 lvitem.Text = sqlreader["mach"].ToString();
155                 lvitem.SubItems.Add(sqlreader["cauhoi"].ToString().Trim());
156                 lvitem.SubItems.Add(sqlreader["A"].ToString().Trim());
157                 lvitem.SubItems.Add(sqlreader["B"].ToString().Trim());
158                 lvitem.SubItems.Add(sqlreader["C"].ToString().Trim());
159                 lvitem.SubItems.Add(sqlreader["D"].ToString().Trim());
160                 lvitem.SubItems.Add(sqlreader["Dapan"].ToString());
161
162                 //lvitem.SubItems.Add(sqlreader["n"].ToString());
163
164                 listView1.Items.Add(lvitem);
165             }
166             sqlreader.Close();
167
168         }
File name: frmCapNhat.cs Copy
183         private void button1_Click_1(object sender, EventArgs e)
184         {
185             try
186             {
187                 string sCauA = textBox1.Text;
188                 string sCauB = textBox2.Text;
189                 string sCauC = textBox3.Text;
190                 string sCauD = textBox4.Text;
191                 string sMaCH = textBox5.Text;
192                 string sCauHoi = richTextBox1.Text;
193                 string sCauDung = "";
194                 string sCauDungLuu = "";
195                 string sTrinhDo = comboBox1.Text;
196                 if (richTextBox1.Text.ToString().Trim() == "" || textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || (checkBox1.Checked == false && checkBox2.Checked == false && checkBox3.Checked == false && checkBox4.Checked == false))
197                 {
198                     MessageBox.Show("Bạn đã sai làm thao tác", "Thông báo");
199                 }
200                 else
201                 {
202                     if (checkBox1.Checked == true)
203                     {
204                         sCauDung = "A";
205                         sCauDungLuu += sCauDung;
206                     }
207                     if (checkBox2.Checked == true)
208                     {
209                         sCauDung = "B";
210                         sCauDungLuu += sCauDung;
211                     }
212                     if (checkBox3.Checked == true)
213                     {
214                         sCauDung = "C";
215                         sCauDungLuu += sCauDung;
216                     }
217                     if (checkBox4.Checked == true)
218                     {
219                         sCauDung = "D";
220                         sCauDungLuu += sCauDung;
221                     }
222
223                     sqlcmd = new SqlCommand("update dapan set A='" + sCauA + "',B='" + sCauB + "',C='" + sCauC + "',D='" + sCauD + "',dapan='" + sCauDungLuu + "' where mach='" + sMaCH + "'", sqlcon);
224                     sqlcmd.ExecuteNonQuery();
225                     sqlcmd = new SqlCommand("update cauhoi set cauhoi='" + sCauHoi + "', trinhdo='" + sTrinhDo + "' where mach='" + sMaCH + "'", sqlcon);
226                     sqlcmd.ExecuteNonQuery();
227                     LoadDataToListView();
228                     Bandau();
229                 }
230             }
231
232             catch
233             {
234                 MessageBox.Show("Bạn đã sai làm thao tác", "Thông báo");
235             }
236         }
File name: Lichsuthi.cs Copy
26         private void timkiemtheodiemcaoanhat()
27         {
28             try
29             {
30                 sqlcmd = new SqlCommand("select ketqua.mats,HOTEN,NGAYTHI,SOCAUDUNG,SOCAUSAI,DIEM FROM THISINHTHI,KETQUA WHERE THISINHTHI.MATS=KETQUA.MATS and ketqua.diem=(select max(diem) from ketqua)", sqlcon);
31                 SqlDataReader sqlreader = sqlcmd.ExecuteReader();
32                 listView1.Items.Clear();
33                 while (sqlreader.Read())
34                 {
35                     ListViewItem lvitem = new ListViewItem();
36                     lvitem.Text = sqlreader["MATS"].ToString();
37                     lvitem.SubItems.Add(sqlreader["HOTEN"].ToString().Trim());
38                     lvitem.SubItems.Add(sqlreader["NGAYTHI"].ToString().Trim());
39                     lvitem.SubItems.Add(sqlreader["SOCAUDUNG"].ToString().Trim());
40                     lvitem.SubItems.Add(sqlreader["SOCAUSAI"].ToString().Trim());
41                     lvitem.SubItems.Add(sqlreader["DIEM"].ToString().Trim());
42                     listView1.Items.Add(lvitem);
43                 }
44                 sqlreader.Close();
45             }
46             catch
47             {
48                 MessageBox.Show("Bạn làm sai thao tác");
49
50             }
51
52
53         }
File name: Lichsuthi.cs Copy
55         private void timkiemtheongay()
56         {
57             if (tbngaythang.Text == "")
58             {
59                 rdb1.Checked = false;
60                 MessageBox.Show("Bạn điền ngày tháng năm vao trước, theo dạng tháng / ngày / năm", "Có lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
61                 tbngaythang.Enabled = true;
62             }
63             else
64             {
65
66                 Sngay = tbngaythang.Text;
67                 try
68                 {
69
70
71                         sqlcmd = new SqlCommand("select thisinhthi.mats,HOTEN,NGAYTHI,SOCAUDUNG,SOCAUSAI,DIEM FROM THISINHTHI,KETQUA WHERE THISINHTHI.MATS=KETQUA.MATS and ngaythi='" + Sngay + "'", sqlcon);
72                         SqlDataReader sqlreader = sqlcmd.ExecuteReader();
73                         listView1.Items.Clear();
74                         while (sqlreader.Read())
75                         {
76                             ListViewItem lvitem = new ListViewItem();
77                             lvitem.Text = sqlreader["MATS"].ToString();
78                             lvitem.SubItems.Add(sqlreader["HOTEN"].ToString().Trim());
79                             lvitem.SubItems.Add(sqlreader["NGAYTHI"].ToString().Trim());
80                             lvitem.SubItems.Add(sqlreader["SOCAUDUNG"].ToString().Trim());
81                             lvitem.SubItems.Add(sqlreader["SOCAUSAI"].ToString().Trim());
82                             lvitem.SubItems.Add(sqlreader["DIEM"].ToString().Trim());
83                             listView1.Items.Add(lvitem);
84                         }
85                         sqlreader.Close();
86
87                 }
88                 catch
89                 {
90                     MessageBox.Show("Không có ai thi ngày này '" + Sngay + "'");
91                     tbngaythang.Text = "";
92
93
94                 }
95             }
96         }
File name: Lichsuthi.cs Copy
97         void timkiemtheodiemthapnhat()
98         {
99             try
100             {
101                 sqlcmd = new SqlCommand("select ketqua.mats,HOTEN,NGAYTHI,SOCAUDUNG,SOCAUSAI,DIEM FROM THISINHTHI,KETQUA WHERE THISINHTHI.MATS=KETQUA.MATS and ketqua.diem=(select min(diem) from ketqua)", sqlcon);
102                 SqlDataReader sqlreader = sqlcmd.ExecuteReader();
103                 listView1.Items.Clear();
104                 while (sqlreader.Read())
105                 {
106                     ListViewItem lvitem = new ListViewItem();
107                     lvitem.Text = sqlreader["MATS"].ToString();
108                     lvitem.SubItems.Add(sqlreader["HOTEN"].ToString().Trim());
109                     lvitem.SubItems.Add(sqlreader["NGAYTHI"].ToString().Trim());
110                     lvitem.SubItems.Add(sqlreader["SOCAUDUNG"].ToString().Trim());
111                     lvitem.SubItems.Add(sqlreader["SOCAUSAI"].ToString().Trim());
112                     lvitem.SubItems.Add(sqlreader["DIEM"].ToString().Trim());
113                     listView1.Items.Add(lvitem);
114                 }
115                 sqlreader.Close();
116             }
117             catch
118             {
119                 MessageBox.Show("Bạn làm sai thao tác");
120
121             }
122         }
File name: Lichsuthi.cs Copy
123         void loadtatca()
124         {
125             try
126             {
127                 sqlcmd = new SqlCommand("select thisinhthi.mats,HOTEN,NGAYTHI,SOCAUDUNG,SOCAUSAI,DIEM FROM THISINHTHI,KETQUA WHERE THISINHTHI.MATS=KETQUA.MATS", sqlcon);
128                 SqlDataReader sqlreader = sqlcmd.ExecuteReader();
129                 listView1.Items.Clear();
130                 while (sqlreader.Read())
131                 {
132                     ListViewItem lvitem = new ListViewItem();
133                     lvitem.Text = sqlreader["MATS"].ToString();
134                     lvitem.SubItems.Add(sqlreader["HOTEN"].ToString().Trim());
135                     lvitem.SubItems.Add(sqlreader["NGAYTHI"].ToString().Trim());
136                     lvitem.SubItems.Add(sqlreader["SOCAUDUNG"].ToString().Trim());
137                     lvitem.SubItems.Add(sqlreader["SOCAUSAI"].ToString().Trim());
138                     lvitem.SubItems.Add(sqlreader["DIEM"].ToString().Trim());
139                     listView1.Items.Add(lvitem);
140                 }
141                 sqlreader.Close();
142             }
143             catch
144             {
145
146                 MessageBox.Show("Dữ liệu trống");
147                 return;
148             }
149         }
File name: PhotonEditor.cs Copy
649     protected virtual void OnGuiSetupCloudAppId()
650     {
651         GUILayout.Label(CurrentLang.AppIdLabel);
652
653         GUILayout.BeginHorizontal();
654         this.cloudAppId = EditorGUILayout.TextField(this.cloudAppId);
655
656         open = GUILayout.Toggle(open, PhotonGUI.HelpIcon, GUIStyle.none, GUILayout.ExpandWidth(false));
657
658         GUILayout.EndHorizontal();
659
660         if (open) GUILayout.Label(CurrentLang.AppIdInfoLabel);
661
662
663
664         EditorGUILayout.Separator();
665
666         GUILayout.Label(CurrentLang.CloudRegionLabel);
667
668         GUILayout.BeginHorizontal();
669         int toolbarValue = GUILayout.Toolbar((int)selectedRegion, CloudServerRegionNames); // the enum CloudRegionCode is converted into a string[] in init (toolbar can't use enum)
670         helpRegion = GUILayout.Toggle( helpRegion, PhotonGUI.HelpIcon, GUIStyle.none, GUILayout.ExpandWidth( false ) );
671         GUILayout.EndHorizontal();
672
673
674         if (helpRegion) GUILayout.Label(CurrentLang.RegionalServersInfo);
675         PhotonEditor.selectedRegion = (CloudRegionCode)toolbarValue;
676
677         EditorGUILayout.Separator();
678
679         GUILayout.BeginHorizontal();
680         if (GUILayout.Button(CurrentLang.CancelButton))
681         {
682             GUIUtility.keyboardControl = 0;
683             this.ReApplySettingsToWindow();
684         }
685
686
687
688         if (GUILayout.Button(CurrentLang.SaveButton))
689         {
690             GUIUtility.keyboardControl = 0;
691             this.cloudAppId = this.cloudAppId.Trim();
692             PhotonEditor.Current.UseCloud(this.cloudAppId);
693
694             PhotonEditor.Current.PreferredRegion = PhotonEditor.selectedRegion;
695             PhotonEditor.Current.HostType = (PhotonEditor.Current.PreferredRegion == CloudRegionCode.none)
696                                                 ? ServerSettings.HostingOption.BestRegion
697                                                 : ServerSettings.HostingOption.PhotonCloud;
698             PhotonEditor.Save();
699
700             Inspect();
701             EditorUtility.DisplayDialog(CurrentLang.SettingsSavedTitle, CurrentLang.SettingsSavedMessage, CurrentLang.OkButton);
702         }
703
704         GUILayout.EndHorizontal();
705
706
707
708         GUILayout.Space(20);
709
710         GUILayout.Label(CurrentLang.SetupOwnServerLabel);
711
712         if (GUILayout.Button(CurrentLang.SelfHostSettingsButton))
713         {
714             //this.photonAddress = ServerSettings.DefaultServerAddress;
715             //this.photonPort = ServerSettings.DefaultMasterPort;
716             this.photonSetupState = PhotonSetupStates.SetupSelfHosted;
717         }
718
719         EditorGUILayout.Separator();
720         GUILayout.Label(CurrentLang.OwnHostCloudCompareLabel);
721         if (GUILayout.Button(CurrentLang.ComparisonPageButton))
722         {
723             Application.OpenURL(UrlCompare);
724         }
725     }
File name: ServerSettingsInspector.cs Copy
17     public override void OnInspectorGUI()
18     {
19         ServerSettings settings = (ServerSettings)this.target;
20
21         #if UNITY_3_5
22         EditorGUIUtility.LookLikeInspector();
23         #endif
24
25
26         settings.HostType = (ServerSettings.HostingOption)EditorGUILayout.EnumPopup("Hosting", settings.HostType);
27         EditorGUI.indentLevel = 1;
28
29         switch (settings.HostType)
30         {
31             case ServerSettings.HostingOption.BestRegion:
32             case ServerSettings.HostingOption.PhotonCloud:
33                 if (settings.HostType == ServerSettings.HostingOption.PhotonCloud)
34                     settings.PreferredRegion = (CloudRegionCode)EditorGUILayout.EnumPopup("Region", settings.PreferredRegion);
35                 settings.AppID = EditorGUILayout.TextField("AppId", settings.AppID);
36                 settings.Protocol = (ConnectionProtocol)EditorGUILayout.EnumPopup("Protocol", settings.Protocol);
37
38                 if (string.IsNullOrEmpty(settings.AppID) || settings.AppID.Equals("master"))
39                 {
40                     EditorGUILayout.HelpBox("The Photon Cloud needs an AppId (GUID) set.\nYou can find it online in your Dashboard.", MessageType.Warning);
41                 }
42                 break;
43
44             case ServerSettings.HostingOption.SelfHosted:
45                 bool hidePort = false;
46                 if (settings.Protocol == ConnectionProtocol.Udp && (settings.ServerPort == 4530 || settings.ServerPort == 0))
47                 {
48                     settings.ServerPort = 5055;
49                 }
50                 else if (settings.Protocol == ConnectionProtocol.Tcp && (settings.ServerPort == 5055 || settings.ServerPort == 0))
51                 {
52                     settings.ServerPort = 4530;
53                 }
54                 #if RHTTP
55                 if (settings.Protocol == ConnectionProtocol.RHttp)
56                 {
57                     settings.ServerPort = 0;
58                     hidePort = true;
59                 }
60                 #endif
61                 settings.ServerAddress = EditorGUILayout.TextField("Server Address", settings.ServerAddress);
62                 settings.ServerAddress = settings.ServerAddress.Trim();
63                 if (!hidePort)
64                 {
65                     settings.ServerPort = EditorGUILayout.IntField("Server Port", settings.ServerPort);
66                 }
67                 settings.Protocol = (ConnectionProtocol)EditorGUILayout.EnumPopup("Protocol", settings.Protocol);
68                 settings.AppID = EditorGUILayout.TextField("AppId", settings.AppID);
69                 break;
70
71             case ServerSettings.HostingOption.OfflineMode:
72                 EditorGUI.indentLevel = 0;
73                 EditorGUILayout.HelpBox("In 'Offline Mode', the client does not communicate with a server.\nAll settings are hidden currently.", MessageType.Info);
74                 break;
75
76             case ServerSettings.HostingOption.NotSet:
77                 EditorGUI.indentLevel = 0;
78                 EditorGUILayout.HelpBox("Hosting is 'Not Set'.\nConnectUsingSettings() will not be able to connect.\nSelect another option or run the PUN Wizard.", MessageType.Info);
79                 break;
80
81             default:
82                 DrawDefaultInspector();
83                 break;
84         }
85
86         if (PhotonEditor.CheckPunPlus())
87         {
88             settings.Protocol = ConnectionProtocol.Udp;
89             EditorGUILayout.HelpBox("You seem to use PUN+.\nPUN+ only supports reliable UDP so the protocol is locked.", MessageType.Info);
90         }
91
92         settings.AppID = settings.AppID.Trim();
93
94         EditorGUI.indentLevel = 0;
95         SerializedObject sObj = new SerializedObject(this.target);
96         SerializedProperty sRpcs = sObj.FindProperty("RpcList");
97         EditorGUILayout.PropertyField(sRpcs, true);
98         sObj.ApplyModifiedProperties();
99
100         GUILayout.BeginHorizontal();
101         GUILayout.Space(20);
102         if (GUILayout.Button("Refresh RPCs"))
103         {
104             PhotonEditor.UpdateRpcList();
105             Repaint();
106         }
107         if (GUILayout.Button("Clear RPCs"))
108         {
109             PhotonEditor.ClearRpcList();
110         }
111         if (GUILayout.Button("Log HashCode"))
112         {
113             Debug.Log("RPC-List HashCode: " + RpcListHashCode() + ". Make sure clients that send each other RPCs have the same RPC-List.");
114         }
115         GUILayout.Space(20);
116         GUILayout.EndHorizontal();
117
118         //SerializedProperty sp = serializedObject.FindProperty("RpcList");
119         //EditorGUILayout.PropertyField(sp, true);
120
121         if (GUI.changed)
122         {
123             EditorUtility.SetDirty(target);
124         }
125     }
File name: NetworkingPeer.cs Copy
3693     public void SetApp(string appId, string gameVersion)
3694     {
3695         this.mAppId = appId.Trim();
3696
3697         if (!string.IsNullOrEmpty(gameVersion))
3698         {
3699             this.mAppVersion = gameVersion.Trim();
3700         }
3701     }

Trim 129 lượt xem

Gõ tìm kiếm nhanh...