Click here to Skip to main content
15,887,585 members
Home / Discussions / C#
   

C#

 
AnswerRe: Change speech recognition language Pin
Dave Kreskowiak13-Sep-15 16:09
mveDave Kreskowiak13-Sep-15 16:09 
GeneralRe: Change speech recognition language Pin
Eddy Vluggen13-Sep-15 21:39
professionalEddy Vluggen13-Sep-15 21:39 
GeneralRe: Change speech recognition language Pin
Richard MacCutchan13-Sep-15 21:54
mveRichard MacCutchan13-Sep-15 21:54 
Questionmysql bracket Pin
abdujalilc12-Sep-15 16:50
abdujalilc12-Sep-15 16:50 
AnswerRe: mysql bracket Pin
Dave Kreskowiak12-Sep-15 16:56
mveDave Kreskowiak12-Sep-15 16:56 
AnswerRe: mysql bracket Pin
Wendelius12-Sep-15 18:28
mentorWendelius12-Sep-15 18:28 
AnswerRe: mysql bracket Pin
Richard Deeming14-Sep-15 2:44
mveRichard Deeming14-Sep-15 2:44 
QuestionC# Change Directory Function Pin
Erics Johnson12-Sep-15 10:59
Erics Johnson12-Sep-15 10:59 
I am trying to solve the following problem but my code is not so good. Could anybody help me a little bit.

Write a function that provides change directory (cd) function for an abstract file system.

Notes:

Root path is '/'.
Path separator is '/'.
Parent directory is addressable as "..".
Directory names consist only of English alphabet letters (A-Z and a-z).

For example, new Path("/a/b/c/d").Cd("../x").CurrentPath should return "/a/b/c/x".

Heres my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

public class Path
{
    public string CurrentPath { get; private set; }

    public Path(string path)
    {
        this.CurrentPath = path;
    }

    public Path Cd(string newPath)
    {
        Path pathStr = new Path(this.CurrentPath);
        if (newPath == null | newPath == string.Empty)
        {
            throw new System.NotSupportedException("Waiting to be implemented.");
        }

        string patternUp = "([\\.]{2}/)+[a-zA-z]+";
        string patternDown = @"/([a-zA-z]*)";

        var matchesUp = Regex.Matches(newPath, patternUp);
        var matchesDown = Regex.Matches(newPath, patternDown);

        if (matchesUp.Count > 0)
        {
            var countUp = newPath.Count(c => c == '.');

            pathStr.CurrentPath = pathStr.CurrentPath.Substring(0, pathStr.CurrentPath.Length - countUp);
            pathStr.CurrentPath = pathStr.CurrentPath + "/" + newPath.Replace("../", "");
        }
        else
        {
            pathStr.CurrentPath = pathStr.CurrentPath  + newPath.Replace("../", "");
        }
        return new Path(pathStr.CurrentPath);
    }

    public static void Main(string[] args)
    {
        Path path = new Path("/a/b/c/d");
        Console.WriteLine(path.Cd("../x").CurrentPath);
    }
}

AnswerRe: C# Change Directory Function Pin
Dave Kreskowiak12-Sep-15 16:52
mveDave Kreskowiak12-Sep-15 16:52 
AnswerRe: C# Change Directory Function Pin
BillWoodruff13-Sep-15 22:07
professionalBillWoodruff13-Sep-15 22:07 
QuestionUnable to work with Multi-Threading Pin
Bastar Media12-Sep-15 4:02
Bastar Media12-Sep-15 4:02 
AnswerRe: Unable to work with Multi-Threading Pin
OriginalGriff12-Sep-15 4:55
mveOriginalGriff12-Sep-15 4:55 
GeneralRe: Unable to work with Multi-Threading Pin
Bastar Media12-Sep-15 20:27
Bastar Media12-Sep-15 20:27 
GeneralRe: Unable to work with Multi-Threading Pin
OriginalGriff12-Sep-15 20:59
mveOriginalGriff12-Sep-15 20:59 
SuggestionRe: Unable to work with Multi-Threading Pin
Richard MacCutchan12-Sep-15 5:42
mveRichard MacCutchan12-Sep-15 5:42 
AnswerRe: Unable to work with Multi-Threading Pin
Pete O'Hanlon12-Sep-15 11:42
mvePete O'Hanlon12-Sep-15 11:42 
QuestionSimple and reusable system for user registration and tracking and auto-updates Pin
Bartosz Jarmuż12-Sep-15 1:02
Bartosz Jarmuż12-Sep-15 1:02 
AnswerRe: Simple and reusable system for user registration and tracking and auto-updates Pin
OriginalGriff12-Sep-15 1:43
mveOriginalGriff12-Sep-15 1:43 
GeneralRe: Simple and reusable system for user registration and tracking and auto-updates Pin
Bartosz Jarmuż12-Sep-15 4:19
Bartosz Jarmuż12-Sep-15 4:19 
AnswerRe: Simple and reusable system for user registration and tracking and auto-updates Pin
Dave Kreskowiak12-Sep-15 3:25
mveDave Kreskowiak12-Sep-15 3:25 
GeneralRe: Simple and reusable system for user registration and tracking and auto-updates Pin
Bartosz Jarmuż12-Sep-15 4:22
Bartosz Jarmuż12-Sep-15 4:22 
QuestionC# RUN zero-based index of the longest run in a string Pin
Erics Johnson11-Sep-15 4:40
Erics Johnson11-Sep-15 4:40 
AnswerRe: C# RUN zero-based index of the longest run in a string Pin
Richard Andrew x6411-Sep-15 5:09
professionalRichard Andrew x6411-Sep-15 5:09 
GeneralRe: C# RUN zero-based index of the longest run in a string Pin
Erics Johnson12-Sep-15 10:56
Erics Johnson12-Sep-15 10:56 
QuestionAdvantages of using .dll files over linking .cs files to projects (for my own generic helper classes / extension methods) Pin
Bartosz Jarmuż11-Sep-15 0:52
Bartosz Jarmuż11-Sep-15 0:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.