lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


The ‘-‘ dash character is a magical character, so it tries to match a pattern.

Lookup string.find in the manual, it has a parameter called ‘plain’ that will disable pattern matching

 

Thijs

 

From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On Behalf Of Austin Einter
Sent: woensdag 25 juni 2014 12:41
To: Lua mailing list
Subject: String usage doubt

 

 

Hi All

I am trying to find the location of a sub string in main string.

The sub string is "Max-Forwards"
The main string looks as shown in below code

 

I am using string.find api to find the location of a substring.

Looks worhen I take substring as "Forwards" it works.

When I take substring as Max-Forward string.find returns nil

Anybody faced this issue




function modify_content_length(msg, length)
local offset = 0
offset = string.find(msg, "Max-Forwards")
if(offset == nil) then
    print("offset = " , offset)
else
    print("offset = " , offset)
end
end

msg = [===["INVITE sips:bob@biloxi.example.com SIP/2.0
Via: SIP/2.0/TLS client.atlanta.example.com:5061;branch=z9hG4bK74bf9
Max-Forwards: 70
From: Alice <sips:alice@atlanta.example.com>;tag=1234567
To: Bob <sips:bob@biloxi.example.com>
Call-ID: 12345601@atlanta.example.com
CSeq: 1 INVITE
Contact: <sips:alice@client.atlanta.example.com>
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY
Supported: replaces
Content-Type: application/sdp
Content-Length:

v=0
o=alice 2890844526 2890844526 IN IP4 client.atlanta.example.com
s=
c=IN IP4 client.atlanta.example.com
t=0 0
m=audio 40000 RTP/AVP 0
a=rtpmap:0 PCMU/8000
]===]

modify_content_length(msg, string.len(msg))