我有一个字符串:"制作牙膏和漱口水的想法"。
我使用下面的代码来获取标签上的最后一个字符串。 结果字符串最后一行:"和一个漱口水。" 但标签显示的最后一行:"牙膏和漱口水" 如何在标签上获得完全字符串的最后一行? 这是我的代码:
#clientform
= form_for(@booking, html: { class: "form-horizontal", role: "form" }) do |f|
- if @booking.errors.any?
.alert.alert-danger.alert-dismissable role="alert"
button.close type="button" data-dismiss="alert"
span aria-hidden="true"
| ×
span.sr-only
| Close
h4= "#{pluralize(@booking.errors.count,"error")} prohibited this booking from being saved:"
ul
- @booking.errors.full_messages.each do |msg|
li= msg
#selectcourse
.form-group
= f.label :course
= f.collection_select :course_id, Course.order(:title),:id,:title, {prompt: "Choose a course", include_blank: true}, {class: "form-control"}
.form-group
.col-sm-12
.next
= link_to 'Next', '#', remote: true, class: "btn btn-primary"
#selectdate
.form-group
= f.label :date
= f.collection_select :date, dates, :to_s, :to_s, include_blank: false
.form-group
.col-sm-12
.next
= link_to 'Next', '#', remote: true, class: "btn btn-primary"
.form-group.hidden
.col-sm-offset-2.col-sm-10
= f.submit class: "btn btn-primary"
答案 0 :(得分:4)
您可以使用NSRange获取代码下方的字符串,以帮助您: -
NSString *strSource=@"The idea of making a toothpaste and a mouthwashg";
NSRange r1 = [strSource rangeOfString:@"toothpaste"];
NSRange r2 = [strSource rangeOfString:@"mouthwashg"];
NSRange rSub = NSMakeRange(r1.location , r2.location + r2.length - r1.location );
NSLog(@"your string:%@",[strSource substringWithRange:rSub]);