Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

public string AnalyzeIt ( string ValueToAnalyze )

Back to Forum: Tech Off
  • User profile image
    candseeme

    #region Analyze Method

    /// <summary>

    /// Method To Remove Leading Spaces Or Symboles Like "/" Or "-"

    /// Found In SomeActionsHere

    /// </summary>

    /// <param name="ValueToAnalyze">String To Analyze</param>

    /// <returns>Returns The String Without These Symboles</returns>

    public string AnalyzeIt ( string ValueToAnalyze )

    {

    /// remove any spaces found

    ValueToAnalyze = ValueToAnalyze.Trim();

    int WhereTheSlash = ValueToAnalyze.IndexOf("/", 0, ValueToAnalyze.Length);

    int WhereTheHyphen = ValueToAnalyze.IndexOf("-", 0, ValueToAnalyze.Length);

    #region the string starts with " so lets analyze it

    if( ValueToAnalyze.StartsWith ( "\"" ) )

    {

    #region If There Is Both a / and - Remove 'em All

    if ( WhereTheSlash != -1 && WhereTheHyphen != -1 )

    {

    if ( WhereTheSlash >= WhereTheHyphen )

    {

    ValueToAnalyze = ValueToAnalyze.Remove

    ( WhereTheHyphen, ValueToAnalyze.Length - WhereTheHyphen );

    ValueToAnalyze = ValueToAnalyze.Trim();

    ValueToAnalyze = ValueToAnalyze.Substring ( 1, ValueToAnalyze.Length - 2 );

    return ValueToAnalyze;

    }

    else

    {

    ValueToAnalyze = ValueToAnalyze.Remove

    ( WhereTheSlash, ValueToAnalyze.Length - WhereTheSlash );

    ValueToAnalyze = ValueToAnalyze.Trim();

    ValueToAnalyze = ValueToAnalyze.Substring (1, ValueToAnalyze.Length - 2 );

    return ValueToAnalyze;

    }

    }

    #endregion

    #region If there is a / in the string remove it

    else if ( WhereTheSlash != -1 )

    {

    ValueToAnalyze = ValueToAnalyze.Remove

    ( WhereTheSlash, ValueToAnalyze.Length - WhereTheSlash );

    ValueToAnalyze = ValueToAnalyze.Trim();

    ValueToAnalyze = ValueToAnalyze.Substring ( 1, ValueToAnalyze.Length - 2 );

    return ValueToAnalyze;

    }

    #endregion

    #region else If there is a - in the string remove it

    else if ( WhereTheHyphen != -1 )

    {

    ValueToAnalyze = ValueToAnalyze.Remove

    ( WhereTheHyphen, ValueToAnalyze.Length - WhereTheHyphen );

    ValueToAnalyze = ValueToAnalyze.Trim();

    ValueToAnalyze = ValueToAnalyze.Substring ( 1, ValueToAnalyze.Length - 2 );

    return ValueToAnalyze;

    }

    #endregion

    #region there is no / or - in the string

    else

    {

    ValueToAnalyze = ValueToAnalyze.Trim();

    ValueToAnalyze = ValueToAnalyze.Substring( 1, ValueToAnalyze.Length - 2 );

    return ValueToAnalyze;

    }

    #endregion

    }

    #endregion

    #region the string does not start with "

    else

    {

    #region If There Is Both a / and - Remove 'em All

    if ( WhereTheSlash != -1 && WhereTheHyphen != -1 )

    {

    if ( WhereTheSlash >= WhereTheHyphen )

    {

    ValueToAnalyze = ValueToAnalyze.Remove

    ( WhereTheHyphen,ValueToAnalyze.Length - WhereTheHyphen );

    ValueToAnalyze = ValueToAnalyze.Trim();

    return ValueToAnalyze;

    }

    else

    {

    ValueToAnalyze = ValueToAnalyze.Remove

    (WhereTheSlash,ValueToAnalyze.Length - WhereTheSlash);

    ValueToAnalyze = ValueToAnalyze.Trim();

    return ValueToAnalyze;

    }

    }

    #endregion

    #region If there is a / in the string remove it

    else if ( WhereTheSlash != -1 )

    {

    ValueToAnalyze = ValueToAnalyze.Remove

    ( WhereTheSlash, ValueToAnalyze.Length - WhereTheSlash );

    ValueToAnalyze = ValueToAnalyze.Trim();

    return ValueToAnalyze;

    }

    #endregion

    #region else If there is a - in the string remove it

    else if ( WhereTheHyphen != -1 )

    {

    ValueToAnalyze = ValueToAnalyze.Remove

    ( WhereTheHyphen, ValueToAnalyze.Length - WhereTheHyphen );

    ValueToAnalyze = ValueToAnalyze.Trim();

    return ValueToAnalyze;

    }

    #endregion

    #region there is no / or - in the string

    else

    {

    ValueToAnalyze = ValueToAnalyze.Trim();

    return ValueToAnalyze;

    }

    #endregion

    }

    #endregion

    }

     

    #endregion


    My Problem is what if an application path conatins this

    c:\windows\take - me.txt

    this method will start trimming from - to the end

    how to solve it

    Thanks

  • User profile image
    cpod

    It might be easier if you explain what it is you are trying to accomplish rather than post code that people will have to workout what it is doing. What is the idea behind your Analyze Method?

  • User profile image
    candseeme

    cpod wrote:
    It might be easier if you explain what it is you are trying to accomplish rather than post code that people will have to workout what it is doing. What is the idea behind your Analyze Method?


    Thanks cpod

    i'm writing a progarm a part of this program is this

    it takes the path to any given file ( object ) and while processing the file to the user it disbalys some info to the enduser like the file's icon
    and in some point when i must deal with following registry key(s)

    ....Windows\Current Version\Run { RunOnce, RunOnceEx }

    some programs launch with parameters

    like that

    c:\windows\notepad.exe D:\Go.txt

    or c:\anydir\myfile /para1 /para2

    or c:\anydir\myfile -para1 /para2

    but some like Inno setup program name its file like that
    Anyname - 123433 - hgo ff.ext

    so the above case is the one i need help with given the code

    Thanks


  • User profile image
    Maurits

    It's typical to place the file name in quotes when it could be confused with a program name with arguments.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.