 |
| Hinweise |
Willkommen im TP-Hilfe-Forum!Dies ist ein Forum zu den Themen Photoshop, Dreamweaver, Flash, Selbständigkeit und mehr, in dem Du Hilfe, Anleitung oder eine Lösung zu Deinen Problemen erhältst. Aktuell bist Du in unseren Foren als Gast mit reinen Leserechten unterwegs. Wenn Du Dich registrierst, kannst Du eigene Themen verfassen, Deine Frage stellen und privat mit anderen TPlern kommunizieren. Weitere Foren werden zugänglich, und Du wirst – falls gewünscht – per Mail über neue Beiträge informiert. Die Registrierung ist schnell und kostenlos. Sollten bei der Registrierung Fragen auftauchen, reicht ein Klick in unsere Hilfe - Häufig gestellte Fragen oder eine kurze Mitteilung an das Support-Team. Viel Spaß bei Traum-Projekt.com |
16.03.2004, 16:24
|
#1
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
Nullen durch Leerzeichen ersetzen
Hey,
ich brauch mal ganz dringend eure Hilfe! Ich lese eine Textdatei zeilenweise aus! Ich muss immer einen Teil der Zeile extrahieren und verändern!
Ab Zeichen 36 nehme ich einen 12 Zeichen langen String hinaus, dieser String beginnt mit einigen Nullen die ich durch Leerzeichen ersetzen muss. Ich muss alle Nullen ersetzten bis die erste andere Ziffer kommt (eventuell darauf folgende Nullen müssen verschont bleiben)! Wäre bis hier eigentlich kein Problem, aber da es pro Zeile verschieden viele Nullen sind mit denen der String anfängt hab ich ein Problem!
Sprich ich habe z.B. folgende extrahierte Strings:
000189002100
000058970020
Der erste String beginnt mit drei Nullen, welche ich durch Leerzeichen ersetzen muss, der zweite mit vier Nullen welche ersetzt gehören!
Könnt ihr mir helfen, ich stehr irgendwie an!
lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
16.03.2004, 16:35
|
#2
|
|
TP-Special Mod
Registriert seit: Jun 2001
Ort: 8°21' O 49°1' N
|
preg_replace(/^0+/, ' ' )
|
|
|
16.03.2004, 16:46
|
#3
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
Hey,
danke für den Tipp! Funktioniert fast perfekt! Das Problem ist das ich pro 0 ein Leerzeichen brauch, jetzt bekomm ich für alle ein einziges!
lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
16.03.2004, 16:56
|
#4
|
|
TP-Special Mod
Registriert seit: Jun 2001
Ort: 8°21' O 49°1' N
|
ups...
preg_replace(/^0+/ g, ' ' )
müsste eigentlich funktionieren...
|
|
|
16.03.2004, 17:00
|
#5
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
Nein, leider nicht!
Fehlermeldung:
Unknown modifier 'g' in ...
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
16.03.2004, 17:17
|
#6
|
|
TP-Specialist
Registriert seit: Jan 2002
Ort: TP/Dynamik
|
es muss nicht immer regex sein:
str_replace("0"," ",$zahl);
__________________
Gehelft? Hier kannst du dich bedanken.
mike
|
|
|
16.03.2004, 17:21
|
#7
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
Dann werden mir aber auch die Nullen geändert die nachher stehen! Ich brauch nur die führenden Nullen, alles nach der ersten anderen Ziffer ist egal!
sprich aus
0000125801450
sollte dann
....125801450 (die Punkte stehen hier für Leerzeichen)
werden.
lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
16.03.2004, 18:02
|
#8
|
|
TP-Specialist
Registriert seit: Jan 2002
Ort: TP/Dynamik
|
wegen sinnlosigkeit zurückgezogen...
__________________
Gehelft? Hier kannst du dich bedanken.
mike
|
|
|
16.03.2004, 18:50
|
#9
|
|
TP-Insider
Registriert seit: Sep 2003
Ort: Sankt Augustin
|
PHP-Code:
$zahl="00000000000012200";
$anzahl=0;
for ($i = 0, $j = strlen($zahl); $i < $j; $i++) {
if (strstr('0', $zahl[i$]) { $anzahl++ }
else { break;}
}
$austauschnull=''; $austauschleer='';
for ($i = 0; $i < $anzahl; $i++) {
$austauchnull.="0";
$austauschleer.=" ";
}
$neuezahl=str_replace($austauschnull,$austauschleer,$zahl);
Das sollte gehen, wenn auch ungetestet. Ich würde das noch in eine Funktion stecken. Ist doch einfacher
$zahl=wegmitnull($zahl);
auszurufen 
__________________
Gruß Sebastian
Webdesign und viel mehr http://lauff.info
yingiz, deine Wirtschaftsgemeinschaft im Netz - gemeinsam bis zu 60% vom Verkaufspreis oder bis zu 300 € Provisionen verdienen. Jeder profitiert von Jedem! Gemeinsam stark! Jetzt anmelden
|
|
|
16.03.2004, 18:59
|
#10
|
|
TP-Special Mod
Registriert seit: Jun 2001
Ort: 8°21' O 49°1' N
|
Auch ned schlecht - die preg_replace-Lösung wird nämlich kniffeliger, als ich dachte.... aber ich sitz dran 
|
|
|
16.03.2004, 19:35
|
#11
|
|
TP-Insider
Registriert seit: Sep 2003
Ort: Sankt Augustin
|
danke bin aber gespannt was man mit regexp noch machen kann
__________________
Gruß Sebastian
Webdesign und viel mehr http://lauff.info
yingiz, deine Wirtschaftsgemeinschaft im Netz - gemeinsam bis zu 60% vom Verkaufspreis oder bis zu 300 € Provisionen verdienen. Jeder profitiert von Jedem! Gemeinsam stark! Jetzt anmelden
|
|
|
16.03.2004, 20:14
|
#12
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
@webmichl: bin auch schon gespannt!
@spl: danke, ich werd es morgen gleich ausprobieren und geb dann bescheid!
lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
16.03.2004, 22:29
|
#13
|
|
TP-Moderator
Registriert seit: Feb 2001
Ort: Helmstedt/Wolfsburg
|
Darf ich mirmachen?
Allein mit Regex bekomm ich's leider nicht hin...  Aber der e-modifier ist schon was feines
PHP-Code:
$zahl = preg_replace("/^0*/e",'str_repeat(" ", strlen("\\\\0"))',$zahl);
Gruss
Jan
|
|
|
17.03.2004, 09:30
|
#14
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
Und der Gewinner ist ...
Stuck Mojo
Ich danke euch allen für die Hilfe!!
lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
17.03.2004, 09:48
|
#15
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
Ich hab gerade was gefunden was wahrscheinlich auch funktioniert hätte!
PHP-Code:
<?PHP
$customer_id = "0000030061971";
$truncate = intval($customer_id );
echo "$truncate";
?>
Output 30061971

__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
|
Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
|
|
|
| Themen-Optionen |
Thema durchsuchen |
|
|
|
| Thema bewerten |
|
|
Forumregeln
|
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.
HTML-Code ist aus.
|
|
|
Alle Zeitangaben in WEZ +2. Es ist jetzt 11:36 Uhr.
|
 |