need help urgently

mirzao

Active member
Joined
Nov 10, 2005
Messages
44
Location
Malaysia
Programming Experience
Beginner
Hi,

If I have a textbox where it contains a string like the following, how can I just pick out the "30A"," 402" and "114.9" and "115.0". Thanx

strs
30A 402

FLASH0(RAM)>temp
Test Site Actual = 114.9€C
Setpoint = 115.0€C
Storage Actual = 114.9€C
Setpoint = 115.0€C


FLASH0(RAM)>
 
Last edited:
Please use more descriptive thread titles in future. Also, this is a string manipulation issue not specifically related to Windows Forms, so I haved moved thios thread from the Windows Forms forum.

The best way to achieve what you want wopuld be to use regular expressions through the System.Text.RegularExpressions namespace. I'm no expert, so I can't tell you exactly how you would do it in this particular case, but that would be the most professional way.

The other alternative is to use string manipulation functions. You've specified a particular string without letting us know what the general case is. I'll assume that what you want is the entire second line and the numerical value of the currency amount from the line that starts with "Test Site Actual". The reason the general case is important is because we don't know for sure whether that will always be the fifth line or not, and also whether it will always contain a euro symbol. Here's a possible solution based on the assumptions above:
VB.NET:
        'Seperate the string into lines.
        Dim lines As String() = System.Text.RegularExpressions.Regex.Split(inputString, Environment.NewLine)

        'Get the second line as the first output.
        Dim firstOutput As String = lines(1)
        Dim secondOutput As String

        For Each line As String In lines
            If line.StartsWith("Test Site Actual") Then
                Dim substringStart As Integer = line.IndexOf("="c) + 1

                secondOutput = line.Substring(substringStart, line.IndexOf("€"c) - substringStart).Trim()
                Exit For
            End If
        Next line
 
Thanks for spending time reading my thread. Sorry for not using the specific title. No, not specifically line 2 and 5 only. Actually there are more lines but what i showed is just a small portion of it .the rest of the lines are similar, only the string that i want to take out.
 
Back
Top