Gsub保留除1个字符以外的所有字符

时间:2017-10-24 02:15:13

标签: gsub

我一直试图替换“。”在我的数据中用“:”,并保持尾随的00,但在切换小数时,我的尾随零消失。是否可以仅切换“。”,同时保持其他所有内容完全相同?我一直在使用:

import { Component} from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';

/**
 * Generated class for the DirectionPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

declare var google;

@Component({
  selector: 'page-direction',
  templateUrl: 'direction.html',
})
export class DirectionPage {

  origin: any;
  destination: any;
  map: any;


  constructor(public navCtrl: NavController, public navParams: NavParams) {
    this.origin = navParams.get('origin');
    this.destination = navParams.get('destination');
    this.map = navParams.get('map');
  }

  ionViewDidLoad() {
    this.calculateRoute();

    console.log('ionViewDidLoad DirectionPage');
  }

  calculateRoute(){
    let mapOptions = {
      center: this.origin,
      zoom: 10,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    this.map = new google.maps.Map(document.getElementById("directionMap"), mapOptions);

    let directionsService = new google.maps.DirectionsService();
    let directionsDisplay = new google.maps.DirectionsRenderer();

    directionsDisplay.setMap(this.map);

    let request = {
      origin: this.origin,
      destination: this.destination,
      travelMode: google.maps.TravelMode.DRIVING
    };

    directionsService.route(request, function(response, status){
      if(status == google.maps.DirectionsStatus.OK){
        directionsDisplay.setDirections(response);
        directionsDisplay.setPanel(document.getElementById('directionPanel'));
      }else{
        console.warn(status);
      }
    });

  }


}

1 个答案:

答案 0 :(得分:1)

您需要先使用format将字符串转换为字符:

gsub("\\.",":",format(df[ ,1]))