Replace the last character of a string in c#

14,777

Solution 1

lat = lat.Substring(0, lat.Length-1) + "2";

Solution 2

lat = lat.Remove(lat.Length - 1) + "2";
Share:
14,777
Sora
Author by

Sora

C# no-jetsu Asp.net no-jetsu Jquery no-jetsu AJAX no-jetsu HTML5 no-jetsu php no-jetsu Telerik no-jetsu you call it magic i call it no-jetsu check out my html5 game using phaser.js i did : http://seekpunk.6te.net/demo.html Feel free to mess around with it and if you need any help in developing html5 games you are welcome to communicate with me on whatsapp :+96170594730 or by email : [email protected] also my github account : https://github.com/balamddine

Updated on June 04, 2022

Comments

  • Sora
    Sora almost 2 years

    I have this string :

     string lat ="24.6669863852163";
    

    how can I replace the last Character '3' by '2' ?

  • Momoro
    Momoro about 4 years
    No offense, but why was there no explanation?
  • Momoro
    Momoro about 4 years
    Substring would be a better choice than Remove