Splitting Strings
The purpose of this article is to teach the reader how to split a string into fragments and use the fragments effectively. Useful for Winsock programs, date commands, and other possible needs.
AI
AIサマリー: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
ソースコード
<p>In order to split a string, you'll need a source. An internal string or a textbox (and so on; any major text source) will do fine. In addition to the source, you'll need something to use it. Look at the code below for a the raw code:<br> <br> output = Split(source, split object)(part number)<br> <br> If you wanted to split a field called Input into two sections, then you'd do the following:<br> <br> <font color="#003399">Private Sub Command1_Click()</font><br> Dim InputString as String<br> Dim Output1 as String<br> Dim Output2 as String<br> <br> 'Sets the input field to a sample string that could be used in a chat program for example<br> InputString = "Particle:::Hello bob!"<br> <br> Output1 = Split(InputString, ":::")(0)<br> Output2 = Split(InputString, ":::")(1)<br> <font color="#003399">Exit Sub</font><br> <br> Alright, do you see how it works? You basically identify what you want split, what sequence to split it at, and which segment to set that particular output string to use. You could go on further with the segment number for if you had something like this perhaps: "Particle:::How's it goin?:::Yo".<br> <br> That code would yield the following:<br> <br> Output1 = "Particle"<br> Output2 = "Hello bob!"<br> <br> Notice that the splitting sequence is removed. Add the following code before the rest if your string may not always have the same number of segments:<br> <br> On Error Resume Next<br> <br> FINAL SAMPLE:<br> <font color="#003399">Private Sub Command1_Click()</font><br> Dim InputString as String<br> Dim Output1 as String<br> Dim Output2 as String<br> Dim Output3 as String<br> <br> 'Sets the input field to a sample string that could be used in a chat program for example<br> InputString = "Particle:::Hello bob!:::Yo"<br> <br> Output1 = Split(InputString, ":::")(0)<br> Output2 = Split(InputString, ":::")(1)<br> Output3 = Split(InputString, ":::")(2)<br> <font color="#003399">Exit Sub</font><br> <br> You don't have to use every segment either. You could use segments 0, 4, and 11 for example.<br> <br> This is also very handy for splitting the Time command, identifying things for winsock applications etc. Use it in the same way, splitting on the ":"s for example.</p>
オリジナルのコメント (3)
Wayback Machineから復元