C помощью нее можно делать следующее:
- Код: Выделить всё
CString s1 = "The angle is %d degrees.";
CString s2;
double angle = 10;
s2.Format(angle, s1);
Получим s2 равное "The angle is 10 degrees."
А в VB есть что-нибудь похожее?
CString s1 = "The angle is %d degrees.";
CString s2;
double angle = 10;
s2.Format(angle, s1);
Получим s2 равное "The angle is 10 degrees."
mystr = "The angle is %d degrees."
myval = 10
msgbox replace(mystr,"%d",cstr(myval),,,vbtextcompare)
Александр Андреев писал(а):А вот это как обойти?
CString s1 = "The first angle is %d degrees. The second angle is %d degrees.";
CString s2;
double angle1 = 10;
double angle2 = 20;
s2.Format(angle1, angle2, s1);
GoGosha писал(а):Александр Андреев писал(а):А вот это как обойти?
CString s1 = "The first angle is %d degrees. The second angle is %d degrees.";
CString s2;
double angle1 = 10;
double angle2 = 20;
s2.Format(angle1, angle2, s1);
Используем её два раза с параметром Count = 1
Dim str As String
Dim angle1 As Double, angle2 As Double
angle1 = 10
angle2 = 20
str = Replace("The first angle is %d degrees. The second angle is %d degrees", "%d", angle1, , 1)
str = Replace(str, "%d", angle2, , 1)
MsgBox str
Private Sub Form_Load()
Dim str As String
Dim angle1 As Double, angle2 As Double
angle1 = 10
angle2 = 20
'str = Replace("The first angle is %d degrees. The second angle is %d degrees", "%d", angle1, , 1)
'str = Replace(str, "%d", angle2, , 1)
str = Format("The first angle is %d degrees. The second angle is %d degrees", 10, 20)
MsgBox str
End Sub
Public Function Format(str As String, ParamArray Replacement() As Variant)
Dim Elem As Variant
Dim Strings As String
Strings = str
For Each Elem In Replacement
Strings = Replace(Strings, "%d", Elem, , 1)
Next Elem
Format = Strings
End Function
GoGosha писал(а):Но если тебе надо ещё и %c %s и др. - то незнаю
Сейчас этот форум просматривают: AhrefsBot, Google-бот и гости: 95