PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
String BEFORE & After extraction of specifc data-VBForums
Results 1 to 10 of 10

Thread: String BEFORE & After extraction of specifc data

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2016
    Posts
    40

    String BEFORE & After extraction of specifc data

    I have the one of the following from data input:

    TRANSPORTATION OF TEMPERATURE CONTROLLED PRODUCT @ -10F (could be any temperature between -10 and 70F)
    - OR -
    TRANSPORTATION OF TEMPERATURE CONTROLLED PRODUCT @ DRY

    I want to extract ONLY -10 or DRY (whichever is present) and place it in another textbox. Notice DRY does not have the "F" after it.

    I suspect a CASE Select will be required but unsure how to pull out only the actual temperature w/o the F

    Currently I'm using code to take only the last 5 character out of the string as follows:


    Code:
    Dim strSetTemp = MyList.Items.Item(196).ToString
    Dim strTemp As String = strSetTemp.Substring(strSetTemp.Length - 5)
    
            Select Case strTemp
                Case "DRY"
                    tbTemp.Text = "DRY"
                Case Else
                    tbTemp.Text = strTemp
            End Select
    Needless to say, this is not working properly and I end up with either "@ DRY" or -10F - as expected. I really need to be able to end up with either "DRY" or "-10" - as my end result. I figured a "between" statement would work but unsure how to properly code this.
    Last edited by K3JAE; Sep 28th, 2019 at 07:28 PM.

  2. #2
    New Member netcoder1337's Avatar
    Join Date
    Sep 2019
    Posts
    11

    Re: String BEFORE & After extraction of specifc data

    Here's one way you can do it.

    vbnet Code:
    1. Dim data As String = "TRANSPORTATION OF TEMPERATURE CONTROLLED PRODUCT @ -10F"
    2. Dim newdata As String = data.Split("@")(1).ToString.Replace("F", "")

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2016
    Posts
    40

    Re: String BEFORE & After extraction of specifc data

    Quote Originally Posted by netcoder1337 View Post
    Here's one way you can do it.

    vbnet Code:
    1. Dim data As String = "TRANSPORTATION OF TEMPERATURE CONTROLLED PRODUCT @ -10F"
    2. Dim newdata As String = data.Split("@")(1).ToString.Replace("F", "")
    This is a no go - still bringing in the F and it is still placing a space in front of the "DRY" which throws off the program.

    I tried adapting to the following:

    Code:
    Dim strSetTemp As String = MyList.Items.Item(196).ToString
    Dim strTemp As String = strSetTemp.Split("@ ")(1).ToString.Replace("F", "")
    AND tried:

    Code:
    Dim strSetTemp As String = MyList.Items.Item(196).ToString
    Dim strTemp As String = strSetTemp.Split("@")(2).ToString.Replace("F", "")
    This results in the space being placed in front of -10 (using the example above). and still puts the f after the -10 which I am trying to eliminate.
    I also need to account for the Space after the "@"sign that I do not want to import.

    The 2nd piece I tried errored with an INDEX error.

    To further Clarify:
    if MyList.Items.Item(196).ToString would equal: "TRANSPORTATION OF TEMPERATURE CONTROLLED PRODUCT @ -10F" - I want to extract ONLY "-10" - no spacing prior and NO F
    if MyList.Items.Item(196).ToString would equal: "TRANSPORTATION OF TEMPERATURE CONTROLLED PRODUCT @ DRY" - I want to extract ONLY "DRY" - no spacing prior.
    Last edited by K3JAE; Sep 29th, 2019 at 05:09 PM.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,415

    Re: String BEFORE & After extraction of specifc data

    netcoder1337's suggestion should do what you want (apart from the space), as long as the characters "F" in the code are exactly the same characters as in your data ("f" is different, and so are other symbols that look similar to ).

    Removing the space should be as simple as using .Trim, eg:
    Code:
    Dim strTemp As String = strSetTemp.Split("@")(1).ToString.Replace("F", "").Trim()
    Quote Originally Posted by K3JAE View Post
    The 2nd piece I tried errored with an INDEX error.
    That is to be expected, because Split() returns an array of strings based on a delimiter, and as there is only one delimiter in the data then the array will have 2 items in it (which have indexes of 0 and 1).

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2016
    Posts
    40

    Re: String BEFORE & After extraction of specifc data

    OK, all understood. One last question please... In the string there is a "" (degree symbol) and note sure the program is interpreting this properly. I say this as when it imports into the program it shows as a "?" in a black diamond in the textbox. Obviously it is not reading that in properly. Is there a way to force that to read it as ALT+0176 ()? I think this may be the issue with the F importing. I still want to drop it but if it is not seeing the degree symbol properly it will not drop it.
    Last edited by K3JAE; Sep 29th, 2019 at 06:35 PM.

  6. #6
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,282

    Re: String BEFORE & After extraction of specifc data

    Quote Originally Posted by K3JAE View Post
    I say this as when it imports into the program it shows as a "?" in a black diamond in the textbox. Obviously it is not reading that in properly.
    Where's the data being imported from, and what code are you using?

    What you describe often happens when you have character data that has been encoded using one of the "Windows" single byte character encodings (often erroneously referred to as ANSI encoding), but then try to decode it back to text by using UTF-8 encoding. When encodings encounter characters they can't decode, they use a fallback strategy (best fit, replacement or exception fallbacks). UTF-8 replacement fallback substiutes character U+FFFD ; a question mark in a black triangle.

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2016
    Posts
    40

    Re: String BEFORE & After extraction of specifc data

    Quote Originally Posted by Inferrd View Post
    Where's the data being imported from, and what code are you using?

    What you describe often happens when you have character data that has been encoded using one of the "Windows" single byte character encodings (often erroneously referred to as ANSI encoding), but then try to decode it back to text by using UTF-8 encoding. When encodings encounter characters they can't decode, they use a fallback strategy (best fit, replacement or exception fallbacks). UTF-8 replacement fallback substiutes character U+FFFD ; a question mark in a black triangle.
    The information is being written to a CSV file from a PDF. When I look at the CSV file the "" (degree symbol) is properly displaying. That same CSV file is what is used to import the date into the program.
    Last edited by K3JAE; Sep 30th, 2019 at 05:20 PM.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,415

    Re: String BEFORE & After extraction of specifc data

    That answers the first part of the question, but not the second part: What code are you using to import it?

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2016
    Posts
    40

    Re: String BEFORE & After extraction of specifc data

    Quote Originally Posted by si_the_geek View Post
    That answers the first part of the question, but not the second part: What code are you using to import it?
    My project is written in VB.

  10. #10
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,282

    Re: String BEFORE & After extraction of specifc data

    VB is the language. If you show the lines of code you are using to import the CSV file, it would help in tracking down the cause of your problems with the wrong characters.

    Most .NET methods that read text files have overloaded definitions that allow you to specify a Text Encoding that is used to decode the bytes in the file back into text. You need to specify the same encoding that was used to create the CSV file or you'll likely end up with the wrong characters.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width