Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

working with strings c#

  • 30-07-2007 9:13am
    #1
    Closed Accounts Posts: 2,616 ✭✭✭


    I have a string, and wnat to repalce spaces with underscores. i have tried this but it doesnt work

    string strTempFileName = strFilename;
    for(int i=0; i<strFilename.Length; i++)
    {
    if(Convert.ToChar(strFilename) == ' ')
    {
    strTempFileName.Remove(i,5);
    strTempFileName.Insert(i,"yer ma");
    }
    }
    strTempFileName = strTempFileName;

    any ideas?


Comments

  • Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭Creamy Goodness


    I have a string, and wnat to repalce spaces with underscores. i have tried this but it doesnt work

    string strTempFileName = strFilename;
    for(int i=0; i<strFilename.Length; i++)
    {
    if(Convert.ToChar(strFilename) == ' ')
    {
    strTempFileName.Remove(i,5);
    strTempFileName.Insert(i,"yer ma");
    }
    }
    strTempFileName = strTempFileName;

    any ideas?

    what is it doing? is it running?

    not a c# head but this is fairly simple.

    in pseudocode
    begin
        str := "some sort of sentence."
    
        for i in str.length
            if str[i] == " "
            then
            str[i] = "_"
        
        print str
    end
    

    also wrap code in [.code][./code] - minus the dots - to improve readability.


  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    There's a function in class String called Replace that will do this for you.


  • Closed Accounts Posts: 2,616 ✭✭✭8k2q1gfcz9s5d4


    fasty wrote:
    There's a function in class String called Replace that will do this for you.

    tried that and it didnt work, it wouldnd work with white space for some reason.
    got it working a neway. thanks


  • Registered Users, Registered Users 2 Posts: 604 ✭✭✭Kai


    Strings are immutable. you need to call it like:

    string str2 = str1.Remove(0, 5);


  • Closed Accounts Posts: 2,616 ✭✭✭8k2q1gfcz9s5d4


    Kai wrote:
    Strings are immutable. you need to call it like:

    string str2 = str1.Remove(0, 5);

    yes, i remember now!


  • Advertisement
Advertisement