Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting String from middle of URL 1

Status
Not open for further replies.

RobbieB

Technical User
Apr 25, 2003
215
US
Someone posted a similar issue but they were looking to extract a string from the end of a line of text and I need to putll it from the middle and haven't been able to come up with a solution. I am using Crystal XI on Widnows XP Pro. I am trying to pull the name from a URL. The data looks like this


In this example I need to pull the "CMARTY1" from this URL. Mid can get me to the name but the length of the name changes for every user so it would need to dynamically adjust to the length of the users name. "Calendar" DOES always follow the name.
Any ideas would be appreciated
 
Try:

whileprintingrecords;
stringvar array MyUrl:= split({table.field},"/");
stringvar Output :="";
numbervar counter;
If instr({table.field},"Calendar") > 0 then
For counter:= 1 ubound(MyUrl) do(
if MyUrl[Counter] = "Calendar" then
Output := MyUrl[Counter-1]
);
Output

-k
 
Try:
stringvar x := split({table.string},"/calendar")[1];
mid(x,instrrev(x,"/")+1)

If "calendar" might not be present, then use the following as a check:

stringvar x := split({table.string},"/calendar")[1];
if instr({table.string},"/calendar") > 0 then
mid(x,instrrev(x,"/")+1) else
{table.string}

-LB
 
Thanks K but this return "TRUE". I need the result to be the users name pulled from the middle of the URL.
 
Thanks lbass, But this just returned everything after "Calendar". I need the name after "Exchange" and before "Calendar".
 
It shouldn't ever return true, where are you placing this code? It needs to be in a formula in the details section.

The last thing in the formula is Output, which is either blank (set in the beginning of the formula) or the value in the URL.

Perhaps you should try:

whileprintingrecords;
stringvar array MyUrl:= split({table.field},"/");
stringvar Output :="";
numbervar counter;
If instr({table.field},"Calendar") > 0 then
(
For counter:= 1 ubound(MyUrl) do(
if MyUrl[Counter] = "Calendar" then
Output := MyUrl[Counter-1]
);
);
Output

Can't test right now, but the theory is sound.

-k
 
K, you are absolutely correct and THANK YOU. When I copied your previous formula I missed the output line. I tried you second formula and though it was missing "to" before "unbound" it worked perfectly after I changed it to "to unbound" Thanks again.
 
Took a minute to work through this item, maybe an option....

//Original String...This is your {table.fieldname}
StringVar s1:="
//Location within string (s1) where "/exchange" begins (col 13)....
NumberVar n1 := InStr(s1,"/exchange",1);

//Location within string (s1) where next "/" is located (col 22)
NumberVar n2 := InStr(n1+1,s1,"/",1);

//Location within string (s1) where the "/" after the desired string is located (col 30)
//indicating the end position of the desired string
NumberVar n3 := Instr(n2+1,s1,"/",1);

//If "calendar" might not be present, then use the following as a check:
If instr(s1,"/exchange") > 0 then
StringVar s2 := Mid(s1, n2+1, ((n3-n2)-1));
else
s1 //your {table.fieldname}


just a thought....:)

jmskarp
 
Thanks jmskarp, I'll check that out.
 
I think you must have implemented my formula incorrectly. The split function with the 1st component specified would return only the part up to "/calendar". The second part of the formula would return the portion after the last "/"--which is now the "/" before name. This is just one formula:

stringvar x := split({table.string},"/calendar")[1];
if instr({table.string},"/calendar") > 0 then
mid(x,instrrev(x,"/")+1) else
{table.string}

If "/calendar" isn't present in a particular string, it would return the entire string or you could replace the final {table.string} with "" or leave off the "else" clause if you wanted an empty string returned.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top