Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting substring from the given string

Posted on 2014-01-08
11
Medium Priority
?
441 Views
Last Modified: 2014-01-18
I have a string variable with this value = <!--#include file="../search/SearchInfo.aspx" -->
Dim sName As String = "<!--#include file="../search/SearchInfo.aspx""
I am looping through the array,the page name keeps on changing.


I want this part "../search/SearchInfo.aspx" or  just page name is also fine SearchInfo.aspx

How to get it.

Thanks
0
Comment
Question by:KavyaVS
[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
  • 4
  • 2
  • +1
11 Comments
 
LVL 11

Expert Comment

by:MajorBigDeal
ID: 39766909
Dim sa() As String = sName.Text.Split(""""c)
Dim sb As String = ""

If sa.Length = 3 Then
    sb = sa(1)
Else
    ' Error
End If
0
 
LVL 9

Assisted Solution

by:Misbah
Misbah earned 200 total points
ID: 39766913
do something similar to this :
int startIndex = sName.IndexOf("\"");
string value = sName.SubString(startIndex);

Open in new window


this code is in C# but I am sure you know how to translate this to VB.NET
0
 
LVL 30

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 1200 total points
ID: 39766939
One more way id you need just file name:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim sName As String = "<!--#include file=""../search/SearchInfo.aspx"""

        ' get substring and remove trailin quotes
        Dim fileName As String = sName.Substring(sName.LastIndexOf("/"c) + 1).Trim(New Char() {""""c})

        MessageBox.Show(fileName)
    End Sub

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:KavyaVS
ID: 39770091
Dim sName As String = "<!--#include file="../search/SearchInfo.aspx" -->"

It is returning       SearchInfo.aspx" -->
But I want SearchInfo.aspx

Thanks
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 39770115
Try something like that:

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim sName As String = "<!--#include file=""../search/SearchInfo.aspx""-->"""

        ' get substring and remove trailin quotes
        Dim rawName As String = sName.Substring(sName.LastIndexOf("/"c) + 1)
        Dim fileName As String = rawName.Substring(0, rawName.IndexOf(""""c))

        MessageBox.Show(fileName)
    End Sub

Open in new window

0
 
LVL 11

Accepted Solution

by:
MajorBigDeal earned 600 total points
ID: 39770126
Dim sa() As String = sName.Text.Split(""""c)

Open in new window

0
 

Author Comment

by:KavyaVS
ID: 39771635
I could able to get the file name.
Dim fileCont As String() = System.IO.File.ReadAllLines(sFile)
I read the file by lines in string array.
How to get the part of the array between specific indexes(Ex:index 10 and 100)

Thanks
0
 
LVL 30

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 1200 total points
ID: 39775176
"How to get the part of the array between specific indexes(Ex:index 10 and 100)"

I'm not quite sure I understand the question. However, if you have and array of strings and want to get a sub-array from existing array (i.e,, only part of an original array) you may use ther following method (see MSDN: http://msdn.microsoft.com/en-us/library/z50k9bft(v=vs.110).aspx)

public T[] GetSubArray<T>(this T[] originalData, int startIndex, int length)
{
    T[] resultingArray = new T[length]; //create new array to copy results to
    Array.Copy(originalData, startIndex, resultingArray , 0, length); //use Array method to copy
    return resultingArray ; // return result
}

Open in new window

0
 

Author Comment

by:KavyaVS
ID: 39780731
I will explain the requirement.
I read the .aspx file line by line in string array .It has include files in the body content. I replaced include files line with its content in string array. Now I want to get the content between body tags.

Do you have any other ideas? file content in the string array. Need to get the content inside the body tags to save it in database.

Thanks
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 39780777
Honestly, I'm pretty confused. The initial task was to get a file name from a path string.
And I believe that the answer was given.

Now you are asking about the content. Can you explain with examples?
0
 

Author Closing Comment

by:KavyaVS
ID: 39791301
Thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

730 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