?
Solved

Get substring.

Posted on 2007-04-05
11
Medium Priority
?
334 Views
Last Modified: 2010-04-23
Given

'3 - La Senza DEV' in variable div.Name.

I just want La Senza DEV. The following does not work.

 selectedDivName = Right(div.Name, 4)
                   
0
Comment
Question by:mathieu_cupryk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 18859929

 selectedDivName = Left(div.Name, div.Name.Length - 4)
0
 
LVL 35

Expert Comment

by:YZlat
ID: 18859941
use this because .NET does not have Left function
selectedDivName = div.Name.Substring(4,div.Name.Length - 1)
0
 
LVL 25

Expert Comment

by:SStory
ID: 18859972
Not sure what language or how you want to determine what you are after.
Your code says, "give me the 4 right most chars which would be " DEV"

If this is Dot Net

then div.name.substring(4) would give you all the chars besides the first 4.

You need to provide more info as to how you are going to determine how many chars from which side you want to get.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mathieu_cupryk
ID: 18859997
DOes not work lol
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18860037
The LEFT and RIGHT functions require the import of the Microsoft.VisualBasic compatibility library.

You're going to run into issues if you have more than one digit at the beginning.

Try selectedDivName  = div.Name.Substring(div.IndexOf("-"c) + 1)
0
 
LVL 35

Expert Comment

by:YZlat
ID: 18860042
try

selectedDivName = div.Name.ToString.Substring(4,div.Name.Length - 1)
0
 
LVL 35

Accepted Solution

by:
YZlat earned 2000 total points
ID: 18860047
or

selectedDivName = div.Name.ToString.Substring(4,div.Name.ToString.Length - 1)
0
 
LVL 3

Expert Comment

by:r1937
ID: 18860461
       '-----Read to end
        Dim MyString As String = "3 - La Senza DEV"
        Dim Start As Integer = 7
        MsgBox(MyString.Substring(Start, MyString.Length - Start))
0
 
LVL 3

Expert Comment

by:r1937
ID: 18860488
       '-----Read to end
        Dim MyString As String = "3 - La Senza DEV"
        Dim Start As Integer = 4
        MsgBox(MyString.Substring(Start, MyString.Length - Start))

        '-----Or if you want old visual basic stuff-----

        MsgBox(Microsoft.VisualBasic.Right(MyString, 12))
0
 
LVL 25

Expert Comment

by:SStory
ID: 18860877
If you want tot use the old VB library do an

imports microsoft.visualbasic at the top of the code.

There's nothing wrong with this. C programmer use their libraries and would be lost without them.
While it's true that you can use substring to accomplish a LEFT or RIGHT, it would be a lot simpler if Microsoft had included a left and right on the String class (even if it just called the substring function internally.  At the least a Right function would have been nice.

The bottom line is that if you have a string

dim s as string="WHATEVER"

if you want the left 4 chars
s.substring(0,4) should give it to you the same as Left(s,4)

If you want the right side minus 4 chars

s.substring(4,s.length-4) will give you this

4 could obviouly be some variable if you like.

s.substring(4) in this example start at the 5th char and gives you all the rest
which would be "EVER"

Given a string, this is how you do Left, and Right
Mid could be accomplished such as
s.substring(4,2) which would return "EV" in this case

Your question seems more than answered by multiple people.

If it isn't then you need to be a lot more specific.  

0
 
LVL 34

Expert Comment

by:Sancler
ID: 18861521
From ".NET Framework Class Library - Strings.Mid Method (String, Int32, Int32)"

>>
Parameters
str
Required. String expression from which characters are returned.

Start
Required. Integer expression. Starting position of the characters to return. If Start is greater than the number of characters in str, the Mid function returns a zero-length string (""). Start is one based.

Length
Optional. Integer expression. Number of characters to return. If omitted or if there are fewer than Length characters in the text (including the character at position Start), all characters from the start position to the end of the string are returned.

[...]

This example uses the Mid function to return a specified number of characters from a string.

Visual Basic
' Creates text string.
Dim TestString As String = "Mid Function Demo"
' Returns "Mid".
Dim FirstWord As String = Mid(TestString, 1, 3)
' Returns "Demo".
Dim LastWord As String = Mid(TestString, 14, 4)
' Returns "Function Demo".
Dim MidWords As String = Mid(TestString, 5)

<<

So, with the data you give, you want - in .NET (not heritage Visual Basic) code - and assuming both selectedDivName and div.Name are declared as Strings

    selectedDivName = Mid(div.Name, 5)

Roger
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question