Sign in to follow this  
Followers 0
Valuater

String in string right... question

11 posts in this topic

why does this noted line ";" return 14 ???

$test = "xxxxxxhttp://domain.comxxxxxxx"

$L_loc = StringInStr($test, "http")

$result = StringTrimLeft( $test, $L_loc -1)
MsgBox(0,"test", "final result = " & $result)

$R_loc = StringInStr($result, ".com", 0, -1); here the problem... shows as 14  ???
MsgBox(0,"test", "final result = " & $R_loc)

$result_2 = StringTrimRight( $result, $R_loc -7)

MsgBox(0,"test", "final result = " & $result_2)

??????

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites



why does this noted line ";" return 14 ???

$test = "xxxxxxhttp://domain.comxxxxxxx"

$L_loc = StringInStr($test, "http")

$result = StringTrimLeft( $test, $L_loc -1)
MsgBox(0,"test", "final result = " & $result)

$R_loc = StringInStr($result, ".com", 0, -1); here the problem... shows as 14  ???
MsgBox(0,"test", "final result = " & $R_loc)

$result_2 = StringTrimRight( $result, $R_loc -7)

MsgBox(0,"test", "final result = " & $result_2)

??????

8)

<{POST_SNAPBACK}>

Because ".com" start at pos 14 when you first remove "xxxxxx" ....

The -1 only means to start the search from right to left, but it still returns the found position from the Left...


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks

then how would i remove the unwanted charactors from the right???

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks

then how would i remove the unwanted charactors from the right???

8)

<{POST_SNAPBACK}>

any of these functions: StringLeft() or StringTrimRight()

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

any of these functions: StringLeft() or StringTrimRight()

<{POST_SNAPBACK}>

got it ..... thanks

$test = "xxwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxhttp://my-domain.comxxxxxssssssssssssssssssssssxx"

$L_loc = StringInStr($test, "http")

$result = StringTrimLeft( $test, $L_loc -1)

$R_loc = StringInStr($result, ".com", 0, -1)

$result_2 = StringLeft( $result, $R_loc +3)

MsgBox(0,"test", "final result = " & $result_2)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

That or you could do StringTrimRight(StringLen - StringInStr)


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

is that a shorter routine...?

and how are you getting the string length?? (from the $R_loc?)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

from whichever variable you are modifying...


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

the position and the length of the "name.com" is unknown

$test = "xxwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxhttp://my-domain.comxxxxxssssssssssssssssssssssxx"

$L_loc = StringInStr($test, "http")

$result = StringTrimLeft( $test, $L_loc -1)

$R_loc = StringInStr($result, ".com", 0, -1)

$result_2 = StringLeft( $result, $R_loc +3)

MsgBox(0,"test", "final result = " & $result_2)

I know this is your area, could you give a little more detail

8)

PS did you notice the rock radio post? (removed min/max)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I think you need to be more specific with what your hoping to achieve. A few questions...

Does the "xxwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxx" on either side of the address always have the same/same amount of characters?

Are you looking to retrieve "name.com" or the full address eg "http://name.com"?

Edit: Made a small script based on the information currently given. It relies upon having "http://" and ".com" in the string.

$Test = "xxwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxhttp://my-domain.comxxxxxssssssssssssssssssssssxx"

$Len = StringLen($Test)

$PosStart = StringInStr($Test, "http://")
$PosEnd = StringInStr($Test, ".com")

If $PosStart <> 0 Then
   $Left = StringTrimLeft($Test, $PosStart - 1)
EndIf

If $PosEnd <> 0 Then
   $Result = StringTrimRight($Left, $Len - ($PosEnd + 3))
EndIf

MsgBox(0,"",$Result)
Edited by Burrup

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0