-
May 10th, 2021, 08:23 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Separateing strings
I need to separate strings, however not looking to use arrays or list to so if I don't have to.
I want to separate by a specific character ("-"). Everything beyond and including the - I want to drop or delete.
So in other words ABC-12 becomes ABC and -12 will be deleted.
What is the best was to do this?
I know about split but that seems overkill for what I want to do.
Thank You
-
May 10th, 2021, 08:29 PM
#2
Re: Separateing strings
The simplest option would be to use String.Split and just take the first element from the resulting array. The alternative would be use String.IndexOf to find the dash and then String.Substring to get the substring before that index. For such little data, the former is not really overkill.
-
May 10th, 2021, 08:30 PM
#3
Re: Separateing strings
I should also mention that you could use a Regex. I'm not very proficient in that area so I won't try to provide the appropriate pattern but, if you want overkill, that's probably the way to go.
-
May 11th, 2021, 06:29 PM
#4
Re: Separateing strings
Code:
Dim newString as String = oldString.SubString(0, oldString.indexOf(“-“))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 12th, 2021, 03:01 AM
#5
Thread Starter
Addicted Member
Re: Separateing strings
Originally Posted by jmcilhinney
The simplest option would be to use String.Split and just take the first element from the resulting array. The alternative would be use String.IndexOf to find the dash and then String.Substring to get the substring before that index. For such little data, the former is not really overkill.
Thanks I went with the substring method.
I just meant that using a list, array etc would be overkill, especially in resources, given that part of it was being discarded.
-
May 12th, 2021, 03:01 AM
#6
Thread Starter
Addicted Member
Re: Separateing strings
Originally Posted by .paul.
Code:
Dim newString as String = oldString.SubString(0, oldString.indexOf(“-“))
That is the route I went.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|