# String.IndexOf wildcard

**URL:** <https://forum.xojo.com/t/string-indexof-wildcard/70262>\
**Category:** General\
**Created:** [May 17, 2022, 8:19am UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262 "2022-05-17T08:19:17Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_van\_der\_Linden](https://forum.xojo.com/user_avatar/forum.xojo.com/alexander_van_der_linden/32/323_2.png) [@Alexander\_van\_der\_Linden](https://forum.xojo.com/u/Alexander_van_der_Linden)\
**Post date:** [May 17, 2022, 8:19am UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/1 "2022-05-17T08:19:17Z")

</div>

I have some scanned texts where the OCR has gone wrong and left me with words that have a space inserted before the last character, so house = ‘house e’ and computer = ‘compute r’, but is not always the case. To fix this I want to use string.indexof and search for chr(32)+ a random single character. I noted that wildcards are not supported. Any idea how to do this?

---

<div class="post-metadata">

**Author:** ![ChristopheDV](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@ChristopheDV](https://forum.xojo.com/u/ChristopheDV)\
**Post date:** [May 17, 2022, 8:28am UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/2 "2022-05-17T08:28:41Z")

</div>

You could use RegEx instead.

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [May 17, 2022, 9:53am UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/3 "2022-05-17T09:53:24Z")

</div>

> [@Alexander\_van\_der\_Linden](#):
>
> Any idea how to do this?

A loop from A to Z?

```auto
for x as integer = 65 to 91
TheString = TheString.replaceall (" " + chr(x) , chr(x))
next

```

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [May 17, 2022, 10:55am UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/4 "2022-05-17T10:55:30Z")

</div>

Nice, very nice.

I never would have thought of that…

---

<div class="post-metadata">

**Author:** ![Carsten\_Belling](https://forum.xojo.com/user_avatar/forum.xojo.com/carsten_belling/32/11665_2.png) [@Carsten\_Belling](https://forum.xojo.com/u/Carsten_Belling)\
**Post date:** [May 17, 2022, 11:01am UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/5 "2022-05-17T11:01:23Z")

</div>

I would search for space in every word. If a word contains one the elemination is special(?).

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [May 17, 2022, 11:01am UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/6 "2022-05-17T11:01:24Z")

</div>

revision: car s becomes carS using the first code above  
So it actually needs to be changed to lower case letters

```auto
for x as integer = 97 to 122
TheString = TheString.replaceall (" " + chr(x) , chr(x))
next

```

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [May 17, 2022, 11:14am UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/7 "2022-05-17T11:14:46Z")

</div>

How do you define a word ?

I think it is when it have a space at left and at right, so…

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [May 17, 2022, 11:20am UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/8 "2022-05-17T11:20:29Z")

</div>

This would replace the first character of every word, essentially removing all spaces.

I would only approach this with regex. Even then, I’d have to be extra careful not to replace lone I’s or A’s. Something like `(/s/D+)/s([b-hj-z]/s)` perhaps.

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [May 17, 2022, 1:04pm UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/9 "2022-05-17T13:04:59Z")

</div>

> [@Thom\_McGrath](#):
>
> This would replace the first character of every word, essentially removing all spaces.

Good point, which I had missed mentally.

---

<div class="post-metadata">

**Author:** ![Alexander\_van\_der\_Linden](https://forum.xojo.com/user_avatar/forum.xojo.com/alexander_van_der_linden/32/323_2.png) [@Alexander\_van\_der\_Linden](https://forum.xojo.com/u/Alexander_van_der_Linden)\
**Post date:** [May 17, 2022, 1:22pm UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/10 "2022-05-17T13:22:53Z")

</div>

Well, my approach would be: load the text into the TextArea, start with looking for the first space+character pair (put the cursor there) and halt. User (me) decides if it should be corrected by deleting the space. If so, delete the space and continue to next space+char pair. This combined action to be put in a method and a hotkey.  
A full auto replacement is not possible, that generates too much errors. A text sample:  
**Mr . Jackson , bein g clos e t o th e hom e o f W . E . Wilsie , wok e hi m u p i n tim e t o se e th e light s o f the machin e befor e i t disappeare d Th e sam e night , H . E . Allatt , postmaste r a t Imperial , wa s awakene d fro m slee p b y a brigh t light shinin g int o his room . Ther e wa s n o moon , th e light wa s though t t o b e a fire, an d Mr . Allat t ros e t o investigate , bu t n o fire wa s found . Lookin g a t his watch , th e tim e wa s discovere d t o b e 1:30 o’clock , an d i t i s believe d tha t th e brilliant ligh t wa s cause d b y the searchligh t fro m this mysteriou s airship .**

[Edit] Now with a fresh look, the string to search for should not be space + Character, but space+char+space and replace that with char+space.

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [May 17, 2022, 2:40pm UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/11 "2022-05-17T14:40:24Z")

</div>

> [@Alexander\_van\_der\_Linden](#):
>
> should not be space + Character, but space+char+space and replace that with char+space

or space+char+period

hous **e** wa **s** on fir **e.**

although even that can’t save **hi m u p i n tim** from being **himupin time**  
although thats become a bit more tricky than ‘words that have a space inserted before the last character’

---

<div class="post-metadata">

**Author:** ![AlbertoD](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@AlbertoD](https://forum.xojo.com/u/AlbertoD)\
**Post date:** [May 17, 2022, 3:15pm UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/12 "2022-05-17T15:15:28Z")

</div>

> [@Alexander\_van\_der\_Linden](#):
>
> [Edit] Now with a fresh look, the string to search for should not be space + Character, but space+char+space and replace that with char+space.

and what will happen with:

> [@Alexander\_van\_der\_Linden](#):
>
> discovere d t o b e 1:30 o’clock ,

Is this a one time ‘problem’?

If possible try to fix the source (scan again with other OCR software/settings).

---

<div class="post-metadata">

**Author:** ![Alexander\_van\_der\_Linden](https://forum.xojo.com/user_avatar/forum.xojo.com/alexander_van_der_linden/32/323_2.png) [@Alexander\_van\_der\_Linden](https://forum.xojo.com/u/Alexander_van_der_Linden)\
**Post date:** [May 17, 2022, 4:28pm UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/13 "2022-05-17T16:28:58Z")

</div>

It are scans and OCR of out-of-print books. So I have the PDF’s. There are many pages with this strange errors.

---

<div class="post-metadata">

**Author:** ![AlbertoD](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@AlbertoD](https://forum.xojo.com/u/AlbertoD)\
**Post date:** [May 17, 2022, 4:39pm UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/14 "2022-05-17T16:39:26Z")

</div>

Do you have the scans or just the OCR?  
If you have the scans, then you may try different OCR software/settings and see if you can get better OCR results.

---

<div class="post-metadata">

**Author:** ![Alexander\_van\_der\_Linden](https://forum.xojo.com/user_avatar/forum.xojo.com/alexander_van_der_linden/32/323_2.png) [@Alexander\_van\_der\_Linden](https://forum.xojo.com/u/Alexander_van_der_Linden)\
**Post date:** [May 17, 2022, 6:31pm UTC](https://forum.xojo.com/t/string-indexof-wildcard/70262/15 "2022-05-17T18:31:32Z")

</div>

Just the text unfortunately…
