Solved

Getting substring from the given string

Posted on 2014-01-08
11
431 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
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 29

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
 

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 29

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 29

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 29

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help on C# Linq query on object 6 53
About delegates in c sharp 3 35
C# Single Form 8 28
Web Form VB.Net  import CSV 4 26
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

17 Experts available now in Live!

Get 1:1 Help Now