Solved

Getting substring from the given string

Posted on 2014-01-08
11
429 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
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 11

Expert Comment

by:MajorBigDeal
Comment Utility
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
Comment Utility
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 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 300 total points
Comment Utility
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
 

Author Comment

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

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

Thanks
0
 
LVL 29

Expert Comment

by:anarki_jimbel
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 11

Accepted Solution

by:
MajorBigDeal earned 150 total points
Comment Utility
Dim sa() As String = sName.Text.Split(""""c)

Open in new window

0
 

Author Comment

by:KavyaVS
Comment Utility
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 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 300 total points
Comment Utility
"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
Comment Utility
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 29

Expert Comment

by:anarki_jimbel
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now