473,406 Members | 2,549 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,406 software developers and data experts.

VB Logic

kirubagari
158 100+
Need some help

I have 2 string

String 1: A-B-C-D

String 2: A-B-C

If the string have 4 token

i need take A and concenate with D

A-D

if i have 3 token like A-B-C

i need take the 1st token A

Please help on this.
Sep 13 '12 #1
6 1854
zmbd
5,501 Expert Mod 4TB
kirubagari,

You've made absolutly no sense to me and I'd like to believe that I am a reasonably intelligent person...

So, do yo want to try that again?
Sep 13 '12 #2
kirubagari
158 100+
Hi zmbd ,
Let me explain again.
I have 2 string.
Expand|Select|Wrap|Line Numbers
  1. TFSGNT-SAH-CMP-PreMeas
  2. ILD-SAH-CMP-Meas-5P25K
If the string have 3 dash in between, i need to grab the 1st value before the first dash
Expand|Select|Wrap|Line Numbers
  1. TFSGNT-SAH-CMP-PreMeas
Expand|Select|Wrap|Line Numbers
  1. TFSGNT
Expand|Select|Wrap|Line Numbers
  1. ILD-SAH-CMP-Meas-5P25K
If the string have 4 dash in between, i need to grab first string and Concatenate
with last string as below
Expand|Select|Wrap|Line Numbers
  1. ILD-5P25K
Sep 13 '12 #3
Hi kirubagari,
You can use the following function.

Expand|Select|Wrap|Line Numbers
  1.     Public Function stringProcessor(ByVal inputString As String) As String
  2.         Dim result As String = String.Empty
  3.         Dim stringList As List(Of String) = inputString.Split("-"c).ToList()
  4.         If stringList.Count > 0 AndAlso stringList.Count = 5 Then
  5.             result = stringList(0) & "-" & stringList(stringList.Count-1)
  6.         ElseIf stringList.Count > 0 AndAlso stringList.Count = 4 Then
  7.             result = stringList(0)
  8.         End If
  9.         Return result
  10.     End Function
Sep 13 '12 #4
zmbd
5,501 Expert Mod 4TB
There are a number of ways to solve this:
Split function comes to mind first http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx. With three hyphens in string you will never return more than four sections so check the return for item count.
Second is the recursive instr to return positions.
Third is a midstring,
and so on with the string functions.http://msdn.microsoft.com/en-us/library/dd789093.aspx... I like the filter; however, I'm old school and arrays were the bread and butter of programming.
Sep 13 '12 #5
LeoT
1
Expand|Select|Wrap|Line Numbers
  1. Public Function FinalStr() As String
  2.     Dim a As String
  3.     Dim b As String
  4.     a = "TFSGNT-SAH-CMP-PreMeas"
  5.     b = "ILD-SAH-CMP-Meas-5P25K"
  6.  
  7.     Dim ar
  8.     Dim br
  9.     Dim intcnt As Integer
  10.     Dim firstStr As String
  11.     Dim secondStr As String
  12.  
  13.     ar = Split(a, "-")
  14.     If UBound(ar) = 3 Then
  15.         firstStr = ar(0)
  16.     End If
  17.  
  18.     br = Split(b, "-")
  19.     If UBound(br) = 4 Then
  20.         secondStr = br(4)
  21.     End If
  22.     'MsgBox firstStr & "-" & secondStr
  23.  
  24.     FinalStr = firstStr & "-" & secondStr
  25.  
  26. End Function
Sep 13 '12 #6
kirubagari
158 100+
Hi Experts ,

Thanks.Able to solve the problem
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim a As String
  3. Dim b As String
  4. ' = "TFSGNT-SAH-CMP-PreMeas"
  5. a = "ILD-SAH-CMP-Meas-5P25K"
  6.  
  7. Dim ar
  8. 'Dim br
  9. Dim intcnt As Integer
  10. Dim firstStr As String
  11. Dim secondStr As String
  12. Dim abc As String
  13.  
  14. ar = Split(a, "-")
  15. If UBound(ar) = 3 Then
  16. FinalStr = ar(0)
  17. ElseIf UBound(ar) = 4 Then
  18. secondStr = ar(4)
  19. firstStr = ar(0)
  20. abc = firstStr & "-" & secondStr
  21. End If
  22.  
  23. End Sub
  24.  
Sep 14 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: A.V.C. | last post by:
Hello, I stuck in a delimma. Where to put the business logic that involves only one update but N number of selects from N tables........with N where conditions
4
by: Simon Harvey | last post by:
Hello Chaps, Me and a collegue have been talking about where the best place to put business logic is. I think that the best place is where Microsoft suggest - in a seperate business logic...
0
by: Al Fatykhov | last post by:
Using MABLE logic engine with existing .NET applications. MABLE web services provide an interface to MABLE business objects and logic. Let us review some technical details of the MABLE web...
0
by: Wim Vanhoof | last post by:
----------------------------------------------------------- WLPE' 06 - CALL FOR PAPERS Workshop on Logic-based Methods in Programming Environments (satellite workshop of ICLP’06) August...
16
by: MS newsgroup | last post by:
I don't have clear reasons why we need business logic layer and data logic layer instead of having only data logic layer. Are there any good reasons for that?
0
by: fiona | last post by:
FOR IMMEDIATE RELEASE Catalyst release low cost logic processing tool 87% of defects in software are errors in logic Yucca Valley, CA, September 2006 - Catalyst Development Corporation,...
14
by: rabbitrun | last post by:
Hi Everyone, I work for a financial company. I am planning to give a presentation to rest of the development team (15 people) here on moving server side logic to client-side javascript for an...
2
by: Chris Zopers | last post by:
Hello, I would like to know what's the best way to implement a business logic layer between my user interface and my database. I would say I'd make a dll-project for the business logic layer...
9
by: SAL | last post by:
Hello, I have a Dataset that I have table adapters in I designed using the designer (DataLayer). I have a business logic layer that immulates the DataLayer which may/may not have additional logic...
15
by: bruno.desthuilliers | last post by:
On 27 juin, 18:09, "John Salerno" <johnj...@NOSPAMgmail.comwrote: For which definitions of "content" and "logic" ??? The point of mvc is to keep domain logic separated from presentation logic,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.