Solved

Getting substring from the given string

Posted on 2014-01-08
11
437 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
Technology Partners: 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: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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.Net remove carriage returns, line feeds and tabbs 5 36
C# DateTime Help 6 47
asp.net repeater server posting 5 38
How does this modal gets closed? 6 42
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

751 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