473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

String manipulation question

Hi,

What would be the best way to remove the following from the start of a
string...

"A1", "A2, "A3", "A4", "A5", "B1, "B2", "B3", "B4", "B5", "C1", "C2", "C3",
"C4", "C5", "D1","D2","D3","D4","D5".

I hope I explained that right. A string will have one of the above strings
as its first two characters and I need them removing from the string.

I tried this...
string1 = replace(string1,"A1","")
string1 = replace(string1,"A2","")
string1 = replace(string1,"A3","")
etc..

and although it works its not very efficient as I would need to do this for
all the above strings!

Cheers,
Paul
Seth Rowe are you out there?!
Nov 10 '06 #1
5 1086
Select case string1.substring(0,2)
case "A1", "A2, "A3", "A4", "A5", "B1, "B2", "B3", "B4", "B5", "C1",
"C2", "C3",
"C4", "C5", "D1","D2","D3","D4","D5"
String1 = string1.substring(2,string1.length-2)
case else
end select
--
Dennis in Houston
"Paul" wrote:
Hi,

What would be the best way to remove the following from the start of a
string...

"A1", "A2, "A3", "A4", "A5", "B1, "B2", "B3", "B4", "B5", "C1", "C2", "C3",
"C4", "C5", "D1","D2","D3","D4","D5".

I hope I explained that right. A string will have one of the above strings
as its first two characters and I need them removing from the string.

I tried this...
string1 = replace(string1,"A1","")
string1 = replace(string1,"A2","")
string1 = replace(string1,"A3","")
etc..

and although it works its not very efficient as I would need to do this for
all the above strings!

Cheers,
Paul
Seth Rowe are you out there?!
Nov 10 '06 #2

"Paul" <ia*@home.co.ukwrote in message
news:Ie********************@pipex.net...
: Hi,
:
: What would be the best way to remove the following from the start of
: a string...
:
: "A1", "A2, "A3", "A4", "A5", "B1, "B2", "B3", "B4", "B5", "C1",
: "C2", "C3", "C4", "C5", "D1","D2","D3","D4","D5".
:
: I hope I explained that right. A string will have one of the above
: strings as its first two characters and I need them removing from
the
: string.
:
: I tried this...
: string1 = replace(string1,"A1","")
: string1 = replace(string1,"A2","")
: string1 = replace(string1,"A3","")
: etc..
:
: and although it works its not very efficient as I would need to do
: this for all the above strings!
:
: Cheers,
: Paul
Several approaches come to mind:
If the strings will *always* start with those values, just strip off
everything that follows:

Newvalue = Mid(OldValue, 3)
If the strings may or may not start with those values, then:

Select Case Left(OldValue, 2)
Case "A1", "A2", "A3", "A4", "A5", _
"B1", "B2", "B3", "B4", "B5", _
"C1", "C2", "C3", "C4", "C5", _
"D1", "D2", "C3", "D4", "D5", _

NewValue = Mid(OldValue, 3)

Case Else

NewValue = OldValue

End Select
Or

If Len(OldValue) < 2 Then
NewValue = OldValue
ElseIf Mid(OldValue, 1, 1) 1 >= "A" AndAlso _
Mid(OldValue, 1, 1) <= "E" Then

If Mid(OldValue, 2, 1) >= "1" AndAlso _
Mid(OldValue, 2, 1) <= "5" Then

NewValue = Mid(OldValue, 3)
Else
NewValue = OldValue
End If
Else
NewValue = OldValue
End If
Or best of all, use a regular expression:

Imports System.Text.RegularExpressions

[...]

Dim Pattern as string = "^[A-Ea-e][1-5].*$"

If Regex.isMatch(OldValue, Pattern) Then
NewValue = Mid(OldValue, 3)
Else
NewValue = OldValue
End If

Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.
Nov 11 '06 #3
Fantastic!
Thanks Dennis and Ralf.

"_AnonCoward" <ab****@uvwxyz.comwrote in message
news:QL******************@southeast.rr.com...
>
"Paul" <ia*@home.co.ukwrote in message
news:Ie********************@pipex.net...
: Hi,
:
: What would be the best way to remove the following from the start of
: a string...
:
: "A1", "A2, "A3", "A4", "A5", "B1, "B2", "B3", "B4", "B5", "C1",
: "C2", "C3", "C4", "C5", "D1","D2","D3","D4","D5".
:
: I hope I explained that right. A string will have one of the above
: strings as its first two characters and I need them removing from
the
: string.
:
: I tried this...
: string1 = replace(string1,"A1","")
: string1 = replace(string1,"A2","")
: string1 = replace(string1,"A3","")
: etc..
:
: and although it works its not very efficient as I would need to do
: this for all the above strings!
:
: Cheers,
: Paul
Several approaches come to mind:
If the strings will *always* start with those values, just strip off
everything that follows:

Newvalue = Mid(OldValue, 3)
If the strings may or may not start with those values, then:

Select Case Left(OldValue, 2)
Case "A1", "A2", "A3", "A4", "A5", _
"B1", "B2", "B3", "B4", "B5", _
"C1", "C2", "C3", "C4", "C5", _
"D1", "D2", "C3", "D4", "D5", _

NewValue = Mid(OldValue, 3)

Case Else

NewValue = OldValue

End Select
Or

If Len(OldValue) < 2 Then
NewValue = OldValue
ElseIf Mid(OldValue, 1, 1) 1 >= "A" AndAlso _
Mid(OldValue, 1, 1) <= "E" Then

If Mid(OldValue, 2, 1) >= "1" AndAlso _
Mid(OldValue, 2, 1) <= "5" Then

NewValue = Mid(OldValue, 3)
Else
NewValue = OldValue
End If
Else
NewValue = OldValue
End If
Or best of all, use a regular expression:

Imports System.Text.RegularExpressions

[...]

Dim Pattern as string = "^[A-Ea-e][1-5].*$"

If Regex.isMatch(OldValue, Pattern) Then
NewValue = Mid(OldValue, 3)
Else
NewValue = OldValue
End If

Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.


Nov 11 '06 #4
Paul,

You have your answer already but I would probably in this case, use a split
command and than loop through the parts.

Cor

"Paul" <ia*@home.co.ukschreef in bericht
news:Ie********************@pipex.net...
Hi,

What would be the best way to remove the following from the start of a
string...

"A1", "A2, "A3", "A4", "A5", "B1, "B2", "B3", "B4", "B5", "C1", "C2",
"C3", "C4", "C5", "D1","D2","D3","D4","D5".

I hope I explained that right. A string will have one of the above
strings as its first two characters and I need them removing from the
string.

I tried this...
string1 = replace(string1,"A1","")
string1 = replace(string1,"A2","")
string1 = replace(string1,"A3","")
etc..

and although it works its not very efficient as I would need to do this
for all the above strings!

Cheers,
Paul
Seth Rowe are you out there?!


Nov 11 '06 #5
>What would be the best way to remove the following from the start of a
>string...

"A1", "A2, "A3", "A4", "A5", "B1, "B2", "B3", "B4", "B5", "C1", "C2",
"C3", "C4", "C5", "D1","D2","D3","D4","D5".
>>>>
I tried this...
string1 = replace(string1,"A1","")
string1 = replace(string1,"A2","")
string1 = replace(string1,"A3","")
etc..
i will try a loop with string = mid$(string,3, len((string)-3))
Nov 11 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CoolPint | last post by:
Is there any way I can reduce the size of internal buffer to store characters by std::string? After having used a string object to store large strings, the object seems to retain the large...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
16
by: zohaibbaloch | last post by:
how to manipulate string without using arrays.manipulation example i have to print dog or any string i want to cut d from dog and paste it a end and add a at the last dog becoms ogda. please...
4
by: Dim | last post by:
I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
7
by: John A Grandy | last post by:
what are the preferred VB.NET analogues for IsNumeric() and Len() and CInt() & similar string-manipulation functions in VB6
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
4
by: yumyu | last post by:
Hi, If i have a Title called " John Smith" and if i press a command button, it changes to "Smith nhoJ" How do i do that with loop and string manipulation? Thanks
14
by: Newbie Coder | last post by:
Hi all, VB.NET 2003 ONLY PLEASE I have a registry key (HKCU\Software\Newbie\SomeKey) of type string which holds an XML string as follows: <root formID="preferencesform" lang="english" ...
13
by: Logan Lee | last post by:
Hi. I've written a small program to learn to write in C. But unfortunately the output is all jumbled up and not nice. /* read_file.c The whole point of this code is to read the entire content...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.