Solved

Getting substring from the given string

Posted on 2014-01-08
11
439 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 50 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 300 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 150 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 300 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

627 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