التابع String.sub
في روبي
< Ruby | String
اذهب إلى التنقل
اذهب إلى البحث
مراجعة 13:23، 11 ديسمبر 2018 بواسطة جميل-بيلوني (نقاش | مساهمات) (إنشاء الصفحة. هذه الصفحة من مساهمات "كريم حبال".)
يعيد التابع sub
ب
البنية العامة
sub(pattern, replacement) → new_str
sub(pattern, hash) → new_str
sub(pattern) {|match| block } → new_str
القيمة المعادة
يعاد
أمثلة
مثال على استعمال التابع sub
:
"hello".sub(/[aeiou]/, '*') #=> "h*llo"
"hello".sub(/([aeiou])/, '<\1>') #=> "h<e>llo"
"hello".sub(/./) {|s| s.ord.to_s + ' ' } #=> "104 ello"
"hello".sub(/(?<foo>[aeiou])/, '*\k<foo>*') #=> "h*e*llo"
'Is SHELL your preferred shell?'.sub(/[[:upper:]]{2,}/, ENV)
#=> "Is /bin/bash your preferred shell?"