Hey, I have a problem.

I have a URL which is something like:
www.WEBSITE.com/player.asp?File_Name=URL_of_The_Video.wmv&Path_Name=URL_Which_Changes

I need to get only the URL of the video.
I know I can get off the: "www.WEBSITE.com/player.asp?File_Name="
out using a string.Replace \ string.Remove
but the address AFTER the video URL is changing.

So what I think I need is a way for the program to start selecting from the word "mms" until the word "wmv" but I don't have any idea how to do that.

Thanks =]

Sorry for the double, I can't edit my original.
but a friend told me to use substring.. I don't know what that means..

Please help :)

Sorry for the double, I can't edit my original.
but a friend told me to use substring.. I don't know what that means..

Please help :)

Okay I can prob help you. A substring will read the String as an index of numbers. below is my string of abreviated months that when a user types the numeric number it finds the appropriate month. This is along the same lines of what you are trying to accomplish. I hope it helps you.

import java.util.Scanner;
public class Month
{
    public static void main(String[] args)
    {
        String monthString = "JanFebMarAprMayJunJulAugSepOctNovDec";
        Scanner myScanner = new Scanner (System.in);
        System.out.print("Enter a month: ");
        String answer = myScanner.nextLine();
        int mon = Integer.parseInt(answer);
        //
        if(mon > 12)
        {
        System.out.print("You have entered an invalid month!!!");
        }
        else
        {
        int start;
        int end;
        end = mon * 3;
        start = end - 3;        
        System.out.println("The month is " + monthString.substring(start,end));
       }
        System.exit(0);
    }
}

Jamesonh20

My appologies, I thought I was in the Java question threads (i bounce back and forth a lot between the two). Much of the code is the same, please reference the MSDN lib on substrings.

Sorry,
Jamesonh20

Sorry, but I can't understand the code \ "translate" it to C#

Perhaps java substring works a little different, this is a translation to C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MonthStrings
{
    class Program
    {      
        static void Main(string[] args)
        {
            string monthString = "JanFebMarAprMayJunJulAugSepOctNovDec";
            Console.WriteLine("Enter a month: ");
            string answer = Console.ReadLine();
            int mon;
            bool succes = int.TryParse(answer, out mon);        
            //        
            if(mon > 12)        
            {        
                Console.WriteLine("You have entered an invalid month!!!");        
            }        
            else        
            {
                int start = (mon - 1) * 3;
                int end = 3;       
                //end = mon * 3;        
                //start = end - 3;                
                Console.WriteLine("The month is " + monthString.Substring(start,end));       
            }
            Console.ReadKey();
}

Perhaps java substring works a little different, this is a translation to C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MonthStrings
{
    class Program
    {      
        static void Main(string[] args)
        {
            string monthString = "JanFebMarAprMayJunJulAugSepOctNovDec";
            Console.WriteLine("Enter a month: ");
            string answer = Console.ReadLine();
            int mon;
            bool succes = int.TryParse(answer, out mon);        
            //        
            if(mon > 12)        
            {        
                Console.WriteLine("You have entered an invalid month!!!");        
            }        
            else        
            {
                int start = (mon - 1) * 3;
                int end = 3;       
                //end = mon * 3;        
                //start = end - 3;                
                Console.WriteLine("The month is " + monthString.Substring(start,end));       
            }
            Console.ReadKey();
}

Thanks, but could I ask you to explain the code?
(it'd be nice if you'd commet it in the end of each line)
:)

If you dont understand the code given for substrings, this may be over your head for now.. but in the interest of completeness you can also use Regular Expressions to match words/patterns/substrings within text.

If you can be sure that your string will always have the same symbols before and after it then substring would be sufficient here.

Heres the above code commented for you to read through:

string monthString = "JanFebMarAprMayJunJulAugSepOctNovDec"; //declare and store the test string to search

            //Console apps use the console window for input and output.
            Console.WriteLine("Enter a month: "); //ask user to enter a month
             string answer = Console.ReadLine(); //readline accepts user input and it is then stored in a string variable
            int mon; //declare a variable to store month converted to integer
            //TryParse has two paramters: the string to parse and the variable to store the result in
            //in this case we are parsing 'answer' and stroing it in 'mon'
            //the method returns a bool value indicating wether the parse was successful or not
            //usually you would use the succes variable to check that the month entered was a number and parsed correctly
            bool succes = int.TryParse(answer, out mon);        
            
            //check if month is not higher than twelve        
            if(mon > 12)        
            {        
                Console.WriteLine("You have entered an invalid month!!!");        
            }        
            else        
            {
                //each month in the test string is 3 characters long. so you can calculate the start position in the string here.
                //month 1 starts at letter 0 = (1-1)*3
                //month 2 starts at letter 3 = (2-1)*3 ...etc
                int start = (mon - 1) * 3;

                //substring accepts a starting point and the length of the string so the end is going to be 3 letters after the start
                //in this instance 'end' is the length of the string you are looking for
                int end = 3;       
             
                //output results:
                //Susbtring will return the characters found starting at 'start' and ending 'end' characters later.
                Console.WriteLine("The month is " + monthString.Substring(start,end));       
            }
            Console.ReadKey();
Comments
Thanks for doing this job for me! :)
This article has been dead for over six months. Start a new discussion instead.