lua-users home
lua-l archive

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


The character "-" is a magic regex character in your find argument. Precede it with % to avoid it being interpreted as such or use the plain argument to find.

From the docs:
string.find (s, pattern [, init [, plain]])

So string.find("xyz-123", "%-123")
Works as expected or
String.find("xyz-123", "-123", 0, true)

Cheers,
Eike

Am 25.06.2014 12:56 schrieb "Austin Einter" <austin.einter@gmail.com>:

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))