Hello,

Tout d'abord bonne année à vous toutes à vous tous.

J ai un soucis d index of of bounds dans une petite routine qui lis mot a mot le contenu d un string

voici mes méthodes :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
private static String constructFormatedText(String value) {
		String result = "";
		int index = 0;
		for (int i = 0 ; i < value.length();i++) {
			String word = readWord(value, index);
			index += word.length();
			System.out.println(word);
		}
		return result;
	}
 
	/**
         * Read the next word in the given String.
         * 
         * @param value
         *                      The value to read
         * @param index
         *                      The begin index
         * @return
         */
	private static String readWord(String value,int index) {
		String result = "";
		int indexStartWord = getIndexOfChar(value,index);
		int indexEndWord = value.indexOf(' ', indexStartWord) + 1;
		String word = value.substring(indexStartWord,indexEndWord);
		return result;
	}
	/**
         * Give the index of the next char.
         * @param value
         *                      The value
         * @return int 
         *                      The index of the char
         */
	private static int getIndexOfChar(String value, int index) {
		int i;
		for (i = index; i < value.length(); i++) {
			char c = value.charAt(i);
			int ascii = (int) c;
			if (ascii >= 33 && ascii <= 126) {
				return i;
			}
		}
		return i;
	}
Et le message d erreur obtenu :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
java.lang.StringIndexOutOfBoundsException: String index out of range: -1475
at java.lang.String.substring(String.java:1938)
at com.odcgroup.page.generation.exporter.TransformationUtils.readWord(TransformationUtils.java:103)
at com.odcgroup.page.generation.exporter.TransformationUtils.constructFormatedXML(TransformationUtils.java:83)
at com.odcgroup.page.generation.exporter.TransformationUtils.getXml(TransformationUtils.java:63)
at com.odcgroup.page.ui.editor.XspTextEditor.updateXspFile(XspTextEditor.java:101)
at com.odcgroup.page.ui.editor.XspTextEditor.activateEditor(XspTextEditor.java:93)
at com.odcgroup.page.ui.PageDesignerEditor.pageChange(PageDesignerEditor.java:168)
at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:239)
quelqu un aurait une piste ?