Codename One不支持String.replace(CharSequence, CharSequence)
,但只支持String.replace(Char, Char)
,如下所示:https://www.codenameone.com/javadoc/java/lang/String.html#replace-char-char-replacing。是否有另一种简单而有效的方法来替换另一个子串?
在我的具体情况下,我需要用一个空字符串替换一个以字符串开头和结尾为特定位置的子字符串,换句话说,删除子字符串。尝试谷歌搜索解决方案,但我遇到的所有解决方案建议使用String.replace
。
答案 0 :(得分:0)
首先,您可以file a RFE添加此内容。有两个版本的替换版本,其中一个使用正则表达式,另一个版本使用常规字符串。我们可以实现另一个。正则表达式替换可能在各个平台上不稳定。
现在你可以这样做:
source 'https://rubygems.org'
ruby '2.2.2'
gem 'rails', '4.2.5'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'sprockets-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'activerecord-session_store'
gem 'quickbooks-ruby','0.4.3'
gem 'acts_as_tree','2.4.0'
# Use Capistrano for deployment
gem 'capistrano', '2.5.19'
gem 'capistrano-ext', '1.2.1'
gem 'rvm-capistrano', require: false
gem 'houston'
gem 'geocoder', '1.2.14'
gem 'dalli'
gem "rmagick", :platforms=>:ruby
gem "rscribd"
gem "rubyzip", '1.1.7',:require => 'zip'
gem "nokogiri", '1.6.7.1'
gem "spreadsheet"
gem "will_paginate" , "3.1.0"
gem "mysql2", '0.4.2', :platforms=>:ruby
gem "newrelic_rpm"
gem "libxml-ruby", :platforms=>:ruby
gem 'fog'
gem 'nas-yahoo_stock'
gem 'jruby-openssl' , :platforms => :jruby
gem 'bouncy-castle-java',"1.5.0146.1" , :platforms => :jruby
gem 'resque', '1.23.1'
gem 'resque-scheduler','1.9.9'
gem 'test-unit', '1.2.3'
gem 'rufus-scheduler', '~> 2.0.9'
gem 'tree_hierarchy', '2.1.1'
gem 'cancancan', '~> 1.9'
gem 'json'
gem 'tilt', '1.4.1'
gem 'httparty', '0.11.0'
gem 'magic_encoding'
gem 'remotipart', '~> 1.2'
gem "galetahub-simple_captcha"
gem "nested_form", :git => "git://github.com/madebydna/nested_form.git", :platforms => :ruby
gem 'aws-s3', :require => 'aws/s3'
gem 'rsolr', :require => 'rsolr'
gem 'rest-client', '1.6.7', :require => 'rest-client'
gem 'fancybox-rails'
gem 'money', '6.6.1'
gem 'fastercsv', '1.5.5'
gem 'american_date', '1.1.0'
gem 'time_diff'
gem "roo", "2.3.0"
gem 'roo-xls'
gem 'oj'
gem 'devise'
gem 'public_activity'
gem 'finance', '~> 2.0.0'
gem 'aws-sdk', '< 2.0'
gem 'byebug'
gem "paperclip", "~> 4.3"
gem 'twitter'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'jvectormap-rails', '~> 1.0.0'
gem "paranoia", "~> 2.0"
gem 'ratyrate'
gem 'zip-zip'
gem 'axlsx', '2.1.0.pre'
gem 'paperclip-av-transcoder'
gem "paperclip-ffmpeg", "~> 1.2.0"
gem 'combine_pdf'
#### Upgraded plugin To Gem ####
gem 'acts_as_commentable'
gem 'dynamic_form'
gem 'exception_notification'
gem 'sidekiq', '4.2.7'
gem 'sidekiq-failures','0.4.5'
gem 'sinatra', :require => nil
gem 'rails-observers'
gem 'ckeditor_rails'
gem 'wicked_pdf', github: 'mileszs/wicked_pdf'#em 'lazyload-rails'
gem "wkhtmltopdf-binary"
gem 'imgkit'
gem 'wkhtmltoimage-binary'
gem 'fusioncharts-rails'
gem 'groupdate'
gem "omnicontacts"
gem 'xirr'
#### Upgraded plugin To Gem ####
group :test do
gem 'rspec-rails'
gem 'cucumber-rails'
gem 'capybara', "1.1.2"
gem 'database_cleaner'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'rails-erd'
gem "rails_best_practices"
gem 'rails-dev-boost'
gem 'rb-inotify', '>= 0.8.8'
gem 'pry'
gem 'pry-rails'
gem 'pry-nav'
gem 'spring'
end
gem 'forecast_io'
gem 'puma'
gem 'actioncable', github: 'rails/actioncable', ref: '6143352f8ffba303f0c7644be7573f6725554cb3'
gem 'link_thumbnailer'
gem 'google-api-client', '~> 0.9', require: 'google/apis/calendar_v3'
gem 'ruby_outlook'
结果将是String result = StringUtil.replaceAll("My original String", "original", "new");
。