# String.search problem

**URL:** <https://forum.kirupa.com/t/string-search-problem/323034>\
**Category:** flash\
**Created:** [June 14, 2011, 5:35pm UTC](https://forum.kirupa.com/t/string-search-problem/323034 "2011-06-14T17:35:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewlong](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@andrewlong](https://forum.kirupa.com/u/andrewlong)\
**Post date:** [June 14, 2011, 5:35pm UTC](https://forum.kirupa.com/t/string-search-problem/323034/1 "2011-06-14T17:35:25Z")

</div>

This seems like it must be ridiculously easy to fix, which is why is it is so frustrating. Essentially actionscript seems to be unable to find question marks in a string (and I have found it responds oddly to periods as well).

I am writing a simple script to append query variables to a URL and need to know if there are already variables there (meaning it already has a question mark in the URL). If it doesnt, it adds the variable with a question mark before it, if it does then it adds the variable with a ampersand before it.

Here is some code with the return values commented next to it. You’ll notice the ? and . returns are always incorrect. I haven’t found any documentation on this, and I am wondering if I have some kind of setting wrong or something.

```auto
var targetUrl = "http://mysite.com?SID=1";
trace(targetUrl,targetUrl.search("?"))//return http://mysite.com?SID=1, -1

var q:String="?.!"
trace(q) //return ?.!
trace(q.search("?"))//return -1
trace(q.search("."))//return 0
trace(q.search("!"))//return 2

var a:String=".?!"
trace(a.search("."))//return 0
trace(a.search("?"))//return -1
trace(a.search("!"))//return 2

var b:String="!?."
trace(b.search("!"))//return 0
trace(b.search("?"))//return -1
trace(b.search("."))//return 0

```
