正在评估/截断字符串中的Ruby全局变量

时间:2017-04-10 22:19:17

标签: ruby-on-rails ruby string escaping

我有一些我需要阅读Ruby的凭据,但问题是他们已经多次重复Private Sub multiEML2MSG() Const PR_ICON_INDEX = &H10800003 Dim objPost As Outlook.PostItem Dim objSafePost As Redemption.SafePostItem Dim objNS As Outlook.NameSpace Dim objInbox As Outlook.MAPIFolder Set objNS = Outlook.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objPost = objInbox.Items.Add(OlItemType.olPostItem) Set objSafePost = New Redemption.SafePostItem Dim xlObj As Excel.Application Dim fd As Office.FileDialog Set xlObj = New Excel.Application Set fd = xlObj.Application.FileDialog(msoFileDialogFolderPicker) With fd .Title = "Select your PST File" .ButtonName = "Ok" .Show If fd.SelectedItems.Count <> 0 Then xDirect$ = fd.SelectedItems(1) & "\" xFname$ = Dir(xDirect$, 7) licznik = 1 Do While xFname$ <> "" XPathEML = xDirect$ & xFname$ XPathMSG = Replace(XPathEML, ".eml", ".msg", , , vbTextCompare) Debug.Print XPath, Replace(XPath, ".eml", ".msg", , , vbTextCompare) objPost.Save objSafePost.Item = objPost objSafePost.Import XPathEML, Redemption.RedemptionSaveAsType.olRFC822 objSafePost.MessageClass = "IPM.Note" objSafePost.Fields(PR_ICON_INDEX) = none objSafePost.SaveAs XPathMSG, Outlook.OlSaveAsType.olMSG xFname$ = Dir licznik = licznik + 1 Loop End If End With xlObj.Quit Set xlObj = Nothing Set objSafePost = Nothing Set objPost = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub 次。所述字符序列的行为如下:

#$

由于某种原因,Ruby会评估> "123#$123" => "123" $1,因为之前没有正则表达式)。有没有办法避免这种情况发生?感谢。

1 个答案:

答案 0 :(得分:1)

使用单引号代替双引号:

irb(main):005:0> '123#$123'    
=> "123\#$123"

或者以其他方式逃避$ char:

irb(main):006:0> "123#\$123"
=> "123\#$123"